Page 1 of 1

Updating just a few colum values in a MySQL DB

Posted: Wed Sep 22, 2010 6:37 pm
by me!
I am getting the "Column count doesn't match value count at row 1" error, I that it is since I am only trying to update two vales in the DB.

My problem is I can't find how to update just the two vales and not the other 14?

This is what I want to do: (but it won't work)

Code: Select all

mysql_query ("UPDATE generators 
            SET    flag_status = 'on', flag_reason = '".pnVarPrepForStore($flag_reason)."'
            WHERE  generator_id ='$generator_id'")
            or die (mysql_error());
In the past I have done things like this:

Code: Select all

mysql_query ("UPDATE generators 
            SET    id = '', size = '', something = '', something_2 = '', flag_status = 'on', flag_reason = '".pnVarPrepForStore($flag_reason)."'
            WHERE  generator_id ='$generator_id'")
            or die (mysql_error());
But wont this overwrite the existing values?

Re: Updating just a few colum values in a MySQL DB

Posted: Wed Sep 22, 2010 6:52 pm
by buckit
You have it formatted correctly (at first glance). One thing that can cause that error is if you are putting in the wrong data into the column type. what does your table structure look like and what is the returned value of pnVarPrepForStore($flag_reason)?

Re: Updating just a few colum values in a MySQL DB

Posted: Wed Sep 22, 2010 7:51 pm
by me!
Hu,

flag_status is a VARCHAR, 2
flag _reason is a VARCHAR, 500

pnVarPrepForStore() is an old Post Nuke function that preps user supplied form input for storage in the DB. Should not be a problem...

Re: Updating just a few colum values in a MySQL DB

Posted: Wed Sep 22, 2010 7:59 pm
by buckit
what about generator_id... is that int? if so then try removing the '' from around it.

if you havent done it already, echo out your SQL statement and see exactly what its returning. sometimes a variable can be returning something you havent expected.

Re: Updating just a few colum values in a MySQL DB

Posted: Wed Sep 22, 2010 8:38 pm
by mikosiko
me! wrote:pnVarPrepForStore() is an old Post Nuke function that preps user supplied form input for storage in the DB. Should not be a problem...
One option... check if your table has a trigger associated or if your pnVarPrepForStore() is accesing/working with some table,

any of both conditions (if present) could be causing the error message and no your Update syntax

Re: Updating just a few colum values in a MySQL DB

Posted: Wed Sep 22, 2010 9:33 pm
by me!
ok Now it is working... :crazy:

Just sat back down at my desk and all is good...
Thanks for the help I thought I was loosing my mind, but now maybe it was my localhost having a nutty!