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 5 years ago.
I am getting error message :
undefined index:
in my code. Below is the function on the line
if($user['flagged'] == 1){
$flag = "Your last payment has been flagged as NOT RECEIVED.";
}
it says Undefined index: flagged
How can this be fixed
Just check if msg index of global array $_GET is set. For example
if(isset($_GET['msg']) && $_GET['msg']==="success")
I think it will solve your problem.
use isset() to check it first
if(isset($_GET['msg']) && $_GET['msg']==="success"){
$log_prompt = '<span style="color:red">You Have successfully registered. Login Now!</span>';
}
if the first condition isset($_GET['msg']) returned false, it will escape the second part of the if condition and will not print your message.
read more about Logical Operators
When you load the page the URL must me something like this:
localhost/your_page.php?msg=something_value
But your app mustn't return error when in URL there isn't ?msg=value... You have to use isset()
if(isset($_GET['msg']) && $_GET['msg'] == "success")
=== is recommended
if(isset($_GET['msg']) && $_GET['msg'] === "success")
More info: http://php.net/manual/en/language.operators.logical.php
Related
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.
Does my code is right?
<?php
if(session_id() == '') {
session_start();
}
if($_SESSION["logged"]== true && isset($_SESSION["userlogged"])) {
header('Location: page.php');
}
?>
what I need to fix because I am getting this error:
Undefined index: logged
for debugging, you might want to update your code from:
if($_SESSION["logged"]== true && isset($_SESSION["userlogged"])) {
header('Location: page.php');
}
to the following:
//isset() checks whether the key exists.
if(isset($_SESSION["logged"]) && $_SESSION["logged"]== true && isset($_SESSION["userlogged"])) {
header('Location: page.php');
} else {
//just for debugging purpose, remove it before pushing it to production.
echo "<pre>";print_r($_SESSION);die();
}
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.
I'll get the error
Notice: Undefined index: page in C:\xampp\htdocs\ajaxx\load_page.php on line 3
This is my full code:
<?php
if(!$_POST['page']) die("0");
$page = $_POST['page'];
if(file_exists('pages/page_'.$page.'.html'))
echo file_get_contents('pages/page_'.$page.'.html');
else echo 'There is no such page!';
?>
It was working yesterday but all of a sudden it gives me this error. The full code is downloaded from A simple AJAX website with jQuery
$_POST['page'] does not exits.
In my experience the $_POST value is always set so doing isset("..") ensures ['page'] is sent. I think 'page' is not been posted. It may be good to do a print_r($_POST) and see what is posted.
if( isset($_POST['Page']) )
{
$page = $_POST['page'];
if(file_exists('pages/page_'.$page.'.html'))
echo file_get_contents('pages/page_'.$page.'.html');
else echo 'There is no such page!';
}
else
echo "Value not posted";
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.
I'm in a ambiguous situation.
Here's the concerned code:
http://prntscr.com/9edm4j
public function verifyReply($reponse)
{
$qr = $this->mStopBOT;
if(isset($_SESSION["stopBOT"]))
{
if($_SESSION["stopBot"] === false)
{
$_SESSION["stopBOT"] = true;
if($qr[$_SESSION["stopBOTq"]][1] == $reponse)
return true;
}
}
return false;
}
And here is the problem:
http://prntscr.com/9ednwm
PHP Notice: Undefined index: stopBot in /home/*************/public_html/inc/classes/Security.inc.php on line 92
The isset() function returns true, but when I use the function, it says that the index is undefined! ?
Regards and Thanks in Advance
You are checking if $_SESSION['stopBOT'] is set but then use $_SESSION['stopBot']
Note the case difference, stopBOT vs stopBot
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.
<?php
$qr_topic = #mysql_query("SELECT * FROM topics");
while ($topic = #mysql_fetch_array($qr_topic)) {
$highlight = "";
**if ($topic['name'] == $_GET['topic'] || $post['topic_id'] == $topic['id']) {**
$highlight = "class='highlight'";
}
echo "<li ".$highlight."><a href='index.php?topic=".$topic['name']."'>".$topic['name']."<img src='img/".$topic['image']."' width='195' height='90' /></a></li>";
}
?>
Getting Undefined index error, not sure what is wrong ? This could be the line for error.
if ($topic['name'] == $_GET['topic'] || $post['topic_id'] == $topic['id']) {**
You try to use $_GET['topic'] without checking if it exists first, that's why you get that error. I'd recommend you to test if the variable exists first using is_set() or empty().
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.
the message is
Notice: Undefined index: flag in C:\xampp\htdocs\myfiles\mobile tracking\index.php on line 63
my code is
<?php
$stat=$_REQUEST['flag'];
if($stat=="FAILED")
{
echo "Username/password doesnot exists";
}
?>
The global variable $_REQUEST['flag'] is probably having value NULL. This is the reason you are getting this error. Well, try using isset(). to check whether the variable is having any value or not.
You should check if the $_REQUEST['flag'] variable has been set:
<?php
$stat= ( isset($_REQUEST['flag']) ? $_REQUEST['flag'] : null) ;
if($stat=="FAILED")
{
echo "Username/password doesnot exists";
}
?>
You received a notice because you didn't initialized the values of the array. Use this construction to prevent them.
if (! array_key_exists('flag', $_REQUEST)) {
$_REQUEST['flag'] = whatever value goes here;
}