Jump to content

Column count doesn't match value count at row 1


jimmyoneshot

Recommended Posts

I am trying to get a php file which copies all the records from one table to another but I get this error when I run it. My query is as follows:-

 

$query = "INSERT INTO userlinks( userid, linkid, categoryid, label, icon, url, favourited ) SELECT linkid, categoryid, label, icon, url FROM links";

 

I think it's to do with the fact that my userlinks table has 2 more columns (userid and favourited) than the links table but into these two columns I simply want to insert the value '1' for userid and 'N' for favourited for each record that gets copied over from the links table. How can I edit my query to do this so it doesn't return this error?  :-\

Link to comment
Share on other sites

Thanks Ken that works. I've modified to include $param_userid which will be dynamic based on what user is logged in i.e. $param_userid is the userid of the user that is currently logged in.

 

Is there any way I can modify this query so that if the records exist FOR that logged in specific user it will update all of these records with the new ones from the links table as well as add in any possible new ones that my client may have add to the links table?

 

Also I've noticed if I run the query it does the insert correctly but if I then go to the userlinks table in mysql and delete all the records and run it again it doesn't. Strange.

 

$query = "INSERT INTO userlinks( userid, linkid, categoryid, label, icon, url, favourited ) SELECT '$param_userid', linkid, categoryid, label, icon, url, "N" FROM links";

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.