Undefined Index: func isset is present [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 9 years ago.
Receiving the following:
Notice: Undefined index: func in /Applications/XAMPP/xamppfiles/htdocs/select2/func.php on line 23
Notice: Undefined index: func in /Applications/XAMPP/xamppfiles/htdocs/select2/func.php on line 67
Notice: Undefined index: func in /Applications/XAMPP/xamppfiles/htdocs/select2/func.php on line 114
Here are the offending lines:
Line 23
if($_GET['func'] == "drop_1" && isset($_GET['func'])) {
drop_1($_GET['drop_var']);
}
function drop_1($drop_var)
{
Line 67
if($_GET['func'] == "drop_2" && isset($_GET['func'])) {
drop_2($_GET['drop_var']);
}
function drop_2($drop_var)
{
Line 114
if($_GET['func'] == "drop_3" && isset($_GET['func'])) {
drop_3($_GET['drop_var']);
}
function drop_3($drop_var)
{
I looked in the existing questions and didn't find an answer where an if statement was attached with the operator &&.
Thanks,

Change the order of your condition to this:
if(isset($_GET['func']) && $_GET['func'] == "drop_1" )
Now you are checking if the 'func' index is set first before using it.

You have the order of your logical operators backwards. First you need to check to see if the variable is set and then you need to check it's value. If the first check is false then the second one will never happen due to short circuiting which prevents the error message you see.
if($_GET['func'] == "drop_1" && isset($_GET['func'])) {
should be:
if(isset($_GET['func']) && $_GET['func'] == "drop_1") {

Related

PHP statement is right? [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.
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();
}

PHP 'illegal offset' [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 5 years ago.
I have a simple PHP blackjack script that I seem to be getting errors in.
The part of code causing the problem is this;
function evaluateHand($hand) {
global $faces;
$value = 0;
foreach ($hand as $card) {
if ($value > 11 && $card['face'] == 'a') {
$value = $value + 1;
}
else {
$value = intval($value) + intval($faces[$card['face']]); <----- error
}
}
return $value;
}
The error is "Warning: Illegal offset 'face'" on the line I've pointed to above.
What's causing this? Or how I could fix it?
Illegal offset means you are requesting an array key that doesn't exist. In this case, the array in $card has no key face when the error is thrown.

undefined index in php page [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 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

Index setted but undefined index [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.
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

Undefined index: topic in C:includes\topic_list.php on line 9 [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.
<?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().

Categories