hno Posted June 6, 2009 Share Posted June 6, 2009 HI I have a insert query that one of the value is:1,0 but when i run the query in php it said :"Column count doesn't match value count at row 1" and i know the problem is from that value so how should write it so that php knows it's the value of one filed. thanks Quote Link to comment https://forums.phpfreaks.com/topic/161184-how-should-write-this-query/ Share on other sites More sharing options...
Alex Posted June 6, 2009 Share Posted June 6, 2009 Show us your query. Quote Link to comment https://forums.phpfreaks.com/topic/161184-how-should-write-this-query/#findComment-850546 Share on other sites More sharing options...
.josh Posted June 6, 2009 Share Posted June 6, 2009 that error means just what it says: you are listing x amount of columns to insert and y amount of values and those 2 numbers don't match. Example that would produce that error: insert into table (column1,column2,column3) values ('a','b') uh oh, you have 3 columns listed but are only providing 2 values... Quote Link to comment https://forums.phpfreaks.com/topic/161184-how-should-write-this-query/#findComment-850556 Share on other sites More sharing options...
hno Posted June 7, 2009 Author Share Posted June 7, 2009 Show us your query. $q="INSERT INTO `shop`.`ad_type` (id,ad_id, $which ,user_id) VALUES (null,'" . $ad_id . "','" .$value . "','" . $uid . "')"; Quote Link to comment https://forums.phpfreaks.com/topic/161184-how-should-write-this-query/#findComment-850806 Share on other sites More sharing options...
Ken2k7 Posted June 7, 2009 Share Posted June 7, 2009 shop is the database name? I assume $which is a column name? If so - $q = "INSERT INTO shop.adtype (ad_id, `$which`, user_id) VALUES ($ad_id, '$value', $uid);"; I added the backticks on which because I don't know its value. Just in case. Quote Link to comment https://forums.phpfreaks.com/topic/161184-how-should-write-this-query/#findComment-850815 Share on other sites More sharing options...
.josh Posted June 7, 2009 Share Posted June 7, 2009 you are using a variable for a column name. Does this mean your table has id, ad_id, user_id and then for instance 5 more columns and you are populating one of them depending on your script? If that is what you are doing, your error is probably because you do not have your columns setup with a default value, so sql expects you to provide a value for all of them, not just one of them. Either include the columns and a null/0/whatever in your query string or else in phpmyadmin ( or however you go directly to your database), set up your columns to have a default value. Quote Link to comment https://forums.phpfreaks.com/topic/161184-how-should-write-this-query/#findComment-850993 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.