lostprophetpunk Posted August 15, 2008 Share Posted August 15, 2008 In my database, I have a table called 'articles'. In that table, I have the following fields... article_id (which is a primary key) article_name entry poster date time But when I try to use the following code to insert values into there, it gives me an error likt eht one shown below the code... $sql = "INSERT INTO `articles` (article_id, article_name, entry, poster, date, time) VALUES('$name' , '$posted', 'today', '4:00pm')"; $res = mysql_query($sql) or die(mysql_error()); The error was - 'Column count doesn't match value count at row 1' So what am I doing wrong? Quote Link to comment Share on other sites More sharing options...
adam84 Posted August 15, 2008 Share Posted August 15, 2008 What the error means is you are giving six column names 'article_id, article_name, entry, poster, date, time', but you are only supplying four values '$name , $posted, today, 4:00pm' You need to give six values $sql = "INSERT INTO `articles` (article_id, article_name, entry, poster, date, time) VALUES(null, '$name' , $entry, '$posted', 'today', '4:00pm')"; Quote Link to comment Share on other sites More sharing options...
fenway Posted August 15, 2008 Share Posted August 15, 2008 And I really hope you don't mean to store "4:00pm" as text. Quote Link to comment Share on other sites More sharing options...
bluejay002 Posted August 16, 2008 Share Posted August 16, 2008 Just kinda curious... why is it you separated date and time as separate fields whereas you can actually combine it as datetime? anyway, that's my insight only, but you might want to take a look at it though Quote Link to comment Share on other sites More sharing options...
Hooker Posted August 16, 2008 Share Posted August 16, 2008 Kill the "date" and "time" fields. $sql = "INSERT INTO `articles` (article_id, article_name, entry, poster, datetime) VALUES(null, '$name' , $entry, '$posted', NOW())"; *twitch* Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.