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? Link to comment https://forums.phpfreaks.com/topic/119812-insert/ 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')"; Link to comment https://forums.phpfreaks.com/topic/119812-insert/#findComment-617318 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. Link to comment https://forums.phpfreaks.com/topic/119812-insert/#findComment-617519 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 Link to comment https://forums.phpfreaks.com/topic/119812-insert/#findComment-617791 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* Link to comment https://forums.phpfreaks.com/topic/119812-insert/#findComment-618222 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.