Page 1 of 2

php errors..

Posted: Wed Apr 20, 2011 11:47 am
by lalamms
hello guys.. im need to solve my problem here..

my first problem is, when im done with my php code, it will display this

"Notice: Undefined index: post in C:\xampp\htdocs\project\post.php on line 7" as my error..

and the second problem is, when i fill up the form in this php, will will display this..

"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1"

can anyone help me solve this problem..

here my php coding..

<html>
<h1>Post news</h1>
<hr>
<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>

<?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");
}

?>
</html>

Re: php errors..

Posted: Wed Apr 20, 2011 11:49 am
by lalamms
im sorry, the error should be in line 17..
sorry for my mistaken..

Re: php errors..

Posted: Wed Apr 20, 2011 12:21 pm
by strafingmoose
Use the PHP tags for your post. I won't count the lines...

Re: php errors..

Posted: Wed Apr 20, 2011 12:24 pm
by lalamms
strafingmoose wrote:Use the PHP tags for your post. I won't count the lines...
can you give me some examples??

the line 17 should start with

if ($_POST ['post'])

Re: php errors..

Posted: Wed Apr 20, 2011 12:28 pm
by fugix
after $date in your insert mysql query you have a , that is not supposed to be there..delete it

Re: php errors..

Posted: Wed Apr 20, 2011 12:32 pm
by strafingmoose
lalamms wrote:
strafingmoose wrote:Use the PHP tags for your post. I won't count the lines...
can you give me some examples??

the line 17 should start with

if ($_POST ['post'])
Use the "PHP Code" button ontop of the text editor.

Re: php errors..

Posted: Wed Apr 20, 2011 12:33 pm
by lalamms
fugix wrote:after $date in your insert mysql query you have a , that is not supposed to be there..delete it
thanks fugix

Re: php errors..

Posted: Wed Apr 20, 2011 12:38 pm
by fugix
did that solve your problem?

Re: php errors..

Posted: Wed Apr 20, 2011 12:43 pm
by lalamms
not really, when i click on submit button, this error will appear..

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1..

and this error still have..

"Notice: Undefined index: post in C:\xampp\htdocs\project\post.php on line 7" as my error..

when the page is done loading.

Re: php errors..

Posted: Wed Apr 20, 2011 12:45 pm
by fugix
show me what your sql lines look like now

Re: php errors..

Posted: Wed Apr 20, 2011 12:50 pm
by lalamms
fugix wrote:show me what your sql lines look like now
i've name my database project, and my table news...

the field is id with auto increment
title with varchar
body with text
and date with date format

Re: php errors..

Posted: Wed Apr 20, 2011 12:52 pm
by fugix
i mean in your php code...where i told you to take out the comma...can i see what the code looks like now please

Re: php errors..

Posted: Wed Apr 20, 2011 12:53 pm
by lalamms
fugix wrote:i mean in your php code...where i told you to take out the comma...can i see what the code looks like now please
sorry, im having diffuculty to understand englis.. huh.

$insert = mysql_query("INSERT INTO news VALUES('','$title','$body','$date')") or die (mysql_error());

Re: php errors..

Posted: Wed Apr 20, 2011 1:01 pm
by fugix
and you still receive the same error?

Re: php errors..

Posted: Wed Apr 20, 2011 1:04 pm
by lalamms
fugix wrote:and you still receive the same error?
yes, i'am