php errors..

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

php errors..

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

Re: php errors..

Post by lalamms »

im sorry, the error should be in line 17..
sorry for my mistaken..
strafingmoose
Forum Newbie
Posts: 15
Joined: Mon Apr 18, 2011 2:56 pm

Re: php errors..

Post by strafingmoose »

Use the PHP tags for your post. I won't count the lines...
lalamms
Forum Newbie
Posts: 21
Joined: Wed Apr 20, 2011 11:19 am

Re: php errors..

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

Re: php errors..

Post by fugix »

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..

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

Re: php errors..

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

Re: php errors..

Post by fugix »

did that solve your problem?
lalamms
Forum Newbie
Posts: 21
Joined: Wed Apr 20, 2011 11:19 am

Re: php errors..

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

Re: php errors..

Post by fugix »

show me what your sql lines look like now
lalamms
Forum Newbie
Posts: 21
Joined: Wed Apr 20, 2011 11:19 am

Re: php errors..

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

Re: php errors..

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

Re: php errors..

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

Re: php errors..

Post by fugix »

and you still receive the same error?
lalamms
Forum Newbie
Posts: 21
Joined: Wed Apr 20, 2011 11:19 am

Re: php errors..

Post by lalamms »

fugix wrote:and you still receive the same error?
yes, i'am
Post Reply