php errors..
Moderator: General Moderators
php errors..
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>
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..
im sorry, the error should be in line 17..
sorry for my mistaken..
sorry for my mistaken..
-
strafingmoose
- Forum Newbie
- Posts: 15
- Joined: Mon Apr 18, 2011 2:56 pm
Re: php errors..
Use the PHP tags for your post. I won't count the lines...
Re: php errors..
can you give me some examples??strafingmoose wrote:Use the PHP tags for your post. I won't count the lines...
the line 17 should start with
if ($_POST ['post'])
Re: php errors..
after $date in your insert mysql query you have a , that is not supposed to be there..delete it
-
strafingmoose
- Forum Newbie
- Posts: 15
- Joined: Mon Apr 18, 2011 2:56 pm
Re: php errors..
Use the "PHP Code" button ontop of the text editor.lalamms wrote:can you give me some examples??strafingmoose wrote:Use the PHP tags for your post. I won't count the lines...
the line 17 should start with
if ($_POST ['post'])
Re: php errors..
thanks fugixfugix wrote:after $date in your insert mysql query you have a , that is not supposed to be there..delete it
Re: php errors..
did that solve your problem?
Re: php errors..
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.
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..
show me what your sql lines look like now
Re: php errors..
i've name my database project, and my table news...fugix wrote:show me what your sql lines look like now
the field is id with auto increment
title with varchar
body with text
and date with date format
Re: php errors..
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..
sorry, im having diffuculty to understand englis.. huh.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
$insert = mysql_query("INSERT INTO news VALUES('','$title','$body','$date')") or die (mysql_error());
Re: php errors..
and you still receive the same error?
Re: php errors..
yes, i'amfugix wrote:and you still receive the same error?