please help me..

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

lalamms
Forum Newbie
Posts: 21
Joined: Wed Apr 20, 2011 11:19 am

please help me..

Post 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>
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

Re: please help me..

Post by fugix »

that is telling you that the submit button has not been pressed yet....so no information is being passed to $_POST['post'].
lalamms
Forum Newbie
Posts: 21
Joined: Wed Apr 20, 2011 11:19 am

Re: please help me..

Post by lalamms »

how to solve this problem?
lalamms
Forum Newbie
Posts: 21
Joined: Wed Apr 20, 2011 11:19 am

Re: please help me..

Post 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??
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

Re: please help me..

Post by fugix »

are you getting this error after you click the submit button or another time?
lalamms
Forum Newbie
Posts: 21
Joined: Wed Apr 20, 2011 11:19 am

Re: please help me..

Post 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'])
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

Re: please help me..

Post 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
lalamms
Forum Newbie
Posts: 21
Joined: Wed Apr 20, 2011 11:19 am

Re: please help me..

Post 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.
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

Re: please help me..

Post by fugix »

no problem..examples of what?
lalamms
Forum Newbie
Posts: 21
Joined: Wed Apr 20, 2011 11:19 am

Re: please help me..

Post by lalamms »

what do you mean before is,

just turn off the error??
is it?
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: please help me..

Post 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().

Code: Select all

isset($_POST['post'])
lalamms
Forum Newbie
Posts: 21
Joined: Wed Apr 20, 2011 11:19 am

Re: please help me..

Post 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().

Code: Select all

isset($_POST['post'])

then, what should i write on this coding??
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

Re: please help me..

Post by fugix »

this....if ($_POST ['post']) should be.....if(isset($_POST['post']))
lalamms
Forum Newbie
Posts: 21
Joined: Wed Apr 20, 2011 11:19 am

Re: please help me..

Post by lalamms »

fugix wrote:this....if ($_POST ['post']) should be.....if(isset($_POST['post']))
the result is still the same..
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

Re: please help me..

Post by fugix »

yeah you cant really get rid of it...it not an important error.. just ignore it
Post Reply