Posting Problems

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

Post Reply
Smackie
Forum Contributor
Posts: 302
Joined: Sat Jan 29, 2005 2:33 pm

Posting Problems

Post 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
ryanlwh
Forum Commoner
Posts: 84
Joined: Wed Sep 14, 2005 1:29 pm

Post 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());
Post Reply