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?  :-\

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";

Archived

This topic is now archived and is closed to further replies.

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