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";
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 7 years ago.
This is my code:
$button = $_GET ['submit'];
$search = $_GET ['search'];
if(!$button)
echo "you didn't submit a keyword!";
else
And I'm getting this error:
Undefined index: search in C:\wamp\www\search1 (2).php on line 4
Use isset() before reading an array key in $_GET/$_POST/$_REQUEST.
$button = isset($_GET['submit']) ? $_GET['submit'] : false;
$search = isset($_GET['search']) ? $_GET['search'] : false;
if(!$button) echo "you didn't submit a keyword!";
PHP Undefined Index
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.
if i write code php same:
<?php
$title = strip_tags($_POST['title']);
?>
unknown error show!
Notice: Undefined index: title in C:\xampp\htdocs\file.php on line 3
$_POST has value, after submitting form, so before that anybody can't use $_POST ..
<?php
if(isset($_POST['title'])){
//Here in condition if(array_key_exists ( 'title' , $_POST )) can also be checked...
//OR if(!empty($_POST)) OR if(!empty($_POST['title'])) can also be put..
$title = strip_tags($_POST['title']);
}
?>
If both form and action in the same page, the first load will show error as there is no data posted. So first checj whether a POST has been made and then assign. Try this
$title = "";
if(isset($_POST['title'])){
$title = strip_tags($_POST['title']);
}
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)
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{
}