Page 1 of 2
please help me..
Posted: Wed Apr 20, 2011 11:24 am
by lalamms
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>
Re: please help me..
Posted: Wed Apr 20, 2011 11:27 am
by fugix
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..
Posted: Wed Apr 20, 2011 11:32 am
by lalamms
how to solve this problem?
Re: please help me..
Posted: Wed Apr 20, 2011 11:42 am
by lalamms
fugix wrote:that is telling you that the submit button has not been pressed yet....so no information is being passed to $_POST['post'].
how to solve this problem??
Re: please help me..
Posted: Wed Apr 20, 2011 12:09 pm
by fugix
are you getting this error after you click the submit button or another time?
Re: please help me..
Posted: Wed Apr 20, 2011 12:20 pm
by lalamms
fugix wrote:are you getting this error after you click the submit button or another time?
its appears before im click the submit button..
and sorry for my mistaken, the coding is
if ($_POST ['post'])
Re: please help me..
Posted: Wed Apr 20, 2011 12:25 pm
by fugix
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..
Posted: Wed Apr 20, 2011 12:26 pm
by lalamms
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
can you give me examples of it??
sorry for noob question..
im new in php.
Re: please help me..
Posted: Wed Apr 20, 2011 12:29 pm
by fugix
no problem..examples of what?
Re: please help me..
Posted: Wed Apr 20, 2011 12:32 pm
by lalamms
what do you mean before is,
just turn off the error??
is it?
Re: please help me..
Posted: Wed Apr 20, 2011 12:33 pm
by McInfo
Look at the error message.
Notice: Undefined index: post
Notice is the
type of error.
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().
Re: please help me..
Posted: Wed Apr 20, 2011 12:37 pm
by lalamms
McInfo wrote:Look at the error message.
Notice: Undefined index: post
Notice is the
type of error.
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().
then, what should i write on this coding??
Re: please help me..
Posted: Wed Apr 20, 2011 12:46 pm
by fugix
this....if ($_POST ['post']) should be.....if(isset($_POST['post']))
Re: please help me..
Posted: Wed Apr 20, 2011 12:52 pm
by lalamms
fugix wrote:this....if ($_POST ['post']) should be.....if(isset($_POST['post']))
the result is still the same..
Re: please help me..
Posted: Wed Apr 20, 2011 12:52 pm
by fugix
yeah you cant really get rid of it...it not an important error.. just ignore it