please help me..
Moderator: General Moderators
please help me..
im done in writing php code.. but this error is out when im running my php page..
Notice: Undefined index: post in C:\xampp\htdocs\project\post.php on line 7
heres my php code, can anyone help me.
<html>
<h1>Post news</h1>
<hr>
<?php
if ($post = $_POST['post'])
{
//get data
$title = &$_POST ['title'];
$body = &$_POST ['body'];
//check existance
if ($title&&$body)
{
mysql_connect("localhost","root","") or die (mysql_error());
mysql_select_db("project") or die (mysql_error());
$date = date('y-m-d');
//insert data
$insert = mysql_query("INSERT INTO news VALUES('','$title','$body','$date',)") or die (mysql_error());
die ("Your news has been posted");
}
else
die ("Please fill out title and body");
}
?>
<form action = 'posts.php' method = 'post'>
Title: <br>
<input type = 'text' name = 'title'><p>
Body: <br>
<textarea rows = '6' cols = '35' name = 'body'></textarea><p>
<input type = 'submit' name = 'post' value = 'Post this news' >
</form>
<hr>
</html>
Notice: Undefined index: post in C:\xampp\htdocs\project\post.php on line 7
heres my php code, can anyone help me.
<html>
<h1>Post news</h1>
<hr>
<?php
if ($post = $_POST['post'])
{
//get data
$title = &$_POST ['title'];
$body = &$_POST ['body'];
//check existance
if ($title&&$body)
{
mysql_connect("localhost","root","") or die (mysql_error());
mysql_select_db("project") or die (mysql_error());
$date = date('y-m-d');
//insert data
$insert = mysql_query("INSERT INTO news VALUES('','$title','$body','$date',)") or die (mysql_error());
die ("Your news has been posted");
}
else
die ("Please fill out title and body");
}
?>
<form action = 'posts.php' method = 'post'>
Title: <br>
<input type = 'text' name = 'title'><p>
Body: <br>
<textarea rows = '6' cols = '35' name = 'body'></textarea><p>
<input type = 'submit' name = 'post' value = 'Post this news' >
</form>
<hr>
</html>
Re: please help me..
that is telling you that the submit button has not been pressed yet....so no information is being passed to $_POST['post'].
Re: please help me..
how to solve this problem?
Re: please help me..
how to solve this problem??fugix wrote:that is telling you that the submit button has not been pressed yet....so no information is being passed to $_POST['post'].
Re: please help me..
are you getting this error after you click the submit button or another time?
Re: please help me..
its appears before im click the submit button..fugix wrote:are you getting this error after you click the submit button or another time?
and sorry for my mistaken, the coding is
if ($_POST ['post'])
Re: please help me..
yeah..that error is normal when you have a $_POST inside of an if statement...just ignore it and turn that error off so you wont see it anymore
Re: please help me..
can you give me examples of it??fugix wrote:yeah..that error is normal when you have a $_POST inside of an if statement...just ignore it and turn that error off so you wont see it anymore
sorry for noob question..
im new in php.
Re: please help me..
no problem..examples of what?
Re: please help me..
what do you mean before is,
just turn off the error??
is it?
just turn off the error??
is it?
Re: please help me..
Look at the error message.
Undefined means something is not yet defined. In other words, something has not been assigned a value. In this case, "undefined" describes an index.
An index (key) is a name that is used to look up a value in an array. In this case, the index is "post" and the array is $_POST.
Altogether, the error message says that you are trying to access an array element that does not exist. You cannot read something that has not been written.
To avoid that error, first test that the element exists with isset().
Notice is the type of error.Notice: Undefined index: post
Undefined means something is not yet defined. In other words, something has not been assigned a value. In this case, "undefined" describes an index.
An index (key) is a name that is used to look up a value in an array. In this case, the index is "post" and the array is $_POST.
Altogether, the error message says that you are trying to access an array element that does not exist. You cannot read something that has not been written.
To avoid that error, first test that the element exists with isset().
Code: Select all
isset($_POST['post'])Re: please help me..
McInfo wrote:Look at the error message.Notice is the type of error.Notice: Undefined index: post
Undefined means something is not yet defined. In other words, something has not been assigned a value. In this case, "undefined" describes an index.
An index (key) is a name that is used to look up a value in an array. In this case, the index is "post" and the array is $_POST.
Altogether, the error message says that you are trying to access an array element that does not exist. You cannot read something that has not been written.
To avoid that error, first test that the element exists with isset().Code: Select all
isset($_POST['post'])
then, what should i write on this coding??
Re: please help me..
this....if ($_POST ['post']) should be.....if(isset($_POST['post']))
Re: please help me..
the result is still the same..fugix wrote:this....if ($_POST ['post']) should be.....if(isset($_POST['post']))
Re: please help me..
yeah you cant really get rid of it...it not an important error.. just ignore it