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.
I am trying to make a library system, everything is going well, but I faced with such a error
Notice: Undefined index: user_log in
C:\xampp\htdocs\e_library\top.php on line 23
and line 23 is here:
<?php
$user_log = $_SESSION['user_log'];
if (isset($_SESSION['user_log'])){
echo "<a href='#' style='color:#FFC'>Welcome $_SESSION[username] </a> || <a href='logout.php' style='color:#FFC'>Logout</a>";
}
else{
echo "<a href='login.php' style='color:#FFC'>Sign In</a>";
}
?>
You should put $user_log = $_SESSION['user_log']; inside your if (isset($_SESSION['user_log'])) block, instead of before.
Please check first:
if (isset($_SESSION['user_log'])){ // Because session array does not contain this yet.
//welcome message and $user_log = ..
}else{
}
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 4 years ago.
I'm getting an undefined offset error
<?php
function ara($one, $two, $three)
{
#preg_match_all('/' . preg_quote($one, '/') .
'(.*?)'. preg_quote($two, '/').'/i', $three, $m);
return #$m[1];
}
$link = "example.com";
$article = file_get_contents($link);
$sport = ara('data-bin="','"',$article);
$channel = ara('data-videobin="','"',$article);
for ($i=0;$i<50;$i++)
echo"<span class='linko'><a target='_blank' href='example.org/live1.php?id=".($channel[$i]."'>$sport[$i]</a>"."<br></span>"); // error is here
?>
How can I fix it? I'am waiting for your helps. Thanks.
These codes are for a live channel website.
The channel variable has less than 50 elements.
Usually in a loop, you should set the end condition to the size of the array.
for ($i=0;$i<sizeof($channel);$i++)
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.
php code:
1. if (isset($data['city_id']))
2. {
3. $city_id = "city_id='". $data['city_id']. "', ";
4. }
And I get:
Notice: Undefined index: city_id on line 3
How can this be?
Just ran your code sample and it works perfectly, I do not get 'undefined index' error - taking us to the big apple
<?php
$data['city_id']='New York';
if (isset($data['city_id']))
{
$city_id = "city_id='". $data['city_id']. "', ";
echo $city_id;
}
?>
output: city_id='New York',
Surely, without the $data['city_index']='New York'; I just get a blank screen, as the if condition is not met - no errors.
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;
}
This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Reference - What does this error mean in PHP?
(38 answers)
Closed 9 years ago.
keep getting this error , can someone explain & help me ..
Notice: Undefined index: error in C:\wamp\www\test\index.php on line 13
the code :
<?php
include "inc/config.php";
include "inc/template.php";
head($title);
openbody($title);
?>
<h1>Sistem Maklumat Kekosongan Jawatan</h1>
<h3>JobsMalaysia Center Danga Bay</h3><br />
<br />
<?php
$err = get_error($_GET['error']);
echo '<p>'.$err.'</p>';
?>
<?php
closebody();
?>
The $_GET super-global doesn't contain the key error, it should be fairly self-explanatory.
You can bypass the error by using:
<?php
if(isset($_GET['error']))
{
$err = get_error($_GET['error']);
echo '<p>'.$err.'</p>';
}
?>