undefined index while update in php issue [PLEASE HELP] [duplicate] - php

This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 4 years ago.
i had a problem in this line, because the error message tell me theres an undefined index:
$strSQL = " UPDATE place SET
rating_value = '".$_POST["rating_value"]."'
WHERE place_id = '".$_POST["place_id"]."'
";
pls help me if you have a solution. thanks

Do you check your variables before do the request like :
if( !empty($_POST["rating_value"]) && !empty($_POST["place_id"]) )
{
// your request
} else {
echo("error");
}

Related

How to fix "Notice: Undefined variable" error [duplicate]

This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 3 years ago.
I am looking at my 'WP_DEBUG' errors and the following two errors/notices pop up in a number of PHP files:
Notice: Undefined variable: defaultUI in...
Notice: Undefined variable: compileShortcodeUI in...
I have checked all of the the PHP files and lines specifically and every single one of these refers to this same bit of code:
$compileShortcodeUI .= "<div class='whatInsert whatInsert_".$shortcodeName."'>".$defaultUI."</div>";
What do I need to change to remove these errors?
You have to define the variable initially.
$compileShortcodeUI = ''; // null or any default value
$defaultUI = ''; // null or any default value
$compileShortcodeUI .= "<div class='whatInsert whatInsert_".$shortcodeName."'>".$defaultUI."</div>";

How to get rid of undefined index in this situation [duplicate]

This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
PHP check value against multiple values with OR-operator
(3 answers)
Closed 4 years ago.
Hi,
I have this code:
if($_GET['s']=="page1" || $_GET['s']=="page2" || $_GET['s']=="page3") {
dosomething();
}
and I get this error: : Undefined index: s in
Which I can dismiss only by adding this line:
$_GET['s']="";
but then this wont execute the code correctly since $_GET['s'] is not supposed to have any initial value. How do I fix this other than disabling the notices and errors?
Thank you.
You can check your $_GET['s']
if(isset($_GET['s'])) {
// your code goes here...
}
isset() is used to check if the index exists.

undefined index email error [duplicate]

This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Can I mix MySQL APIs in PHP?
(4 answers)
Closed 5 years ago.
I'm having a problem here
This is my forgot pass.php code
<?php
if(isset($_POST['submit_email']) && $_POST['email'])
{
require 'connect.php';
include 'connect.php';
$select=mysqli_query($con, "SELECT * from `users` where email='$email'");
if(mysqli_num_rows($select)==1)
{
while($row=mysql_fetch_array($select))
{
$email=($row['email']);
$pass=md5($row['password']);
}
I'm getting the error Undefined variable: email on line 6.
Thanks in advance for helping

i am i getting notice: undefined pss [duplicate]

This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 7 years ago.
here is my php. the session ps comes from a another php page. it comes successfully. but i am getting undefined when i try to use it on the following code to connect to my db.
<?php
$pss = "";
session_start();
if(isset($_SESSION['ps'])){
$pss = $_SESSION['ps'];
}
echo $pss;
$connect = mysqli_connect("localhost","root","","erthiph_asksheikh851821217");
mysqli_query($connect,"INSERT INTO `as_questions`(`Qid`, `M_class`, `S_class`, `Question`, `Answer`, `Doctor`, `Time`) VALUES
('','','','".$pss."','','',CURRENT_TIMESTAMP)");
?>
the above code works. i replaced '$_POST[postquestion]' with '".#pss."'
please check edit history to check edits.
change '$_POST[$pss]' to '".$pss."'

Getting Undefined index error [duplicate]

This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 8 years ago.
Im getting the following error: Notice:undefined index:done
please advise what is wrong
<?php
if($_Get['done']==1 $msg = "Account details saved";
?>
Check first if the key exists, then the comparison to 1.
if (isset($_GET['done']) && $_GET['done'] == 1) {
$msg = '...';
}

Categories