Jump to content

How should write this query


hno

Recommended Posts

 

 

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

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.