Page 1 of 1

Posting Problems

Posted: Thu Sep 15, 2005 11:03 pm
by Smackie
Im making a news postings for my friend for his site and well for some reason i keep coming up with this problem :?
Column count doesn't match value count at row 1
here is the script.

Code: Select all

<?php
include 'db.php';
$username = $_GET['username'];
$news = $_GET['news'];

mysql_query("INSERT INTO news (username, news, date) VALUES ('".$username.", ".$news."', now())") or die(MySQL_Error());
header("Location: http://www.webcom-online.org");
?>
Thank you

Posted: Thu Sep 15, 2005 11:14 pm
by ryanlwh
i guess it's this line:

Code: Select all

mysql_query("INSERT INTO news (username, news, date) VALUES ('".$username.", ".$news."', now())") or die(MySQL_Error());
between $username and $news there should be single quotes around the comma:

Code: Select all

mysql_query("INSERT INTO news (username, news, date) VALUES ('".$username."', '".$news."', now())") or die(MySQL_Error());
a less error-prone approach:

Code: Select all

mysql_query("INSERT INTO news (username, news, date) VALUES ('$username', '$news', now())") or die(MySQL_Error());