Updating just a few colum values in a MySQL DB

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
me!
Forum Contributor
Posts: 133
Joined: Sat Nov 04, 2006 8:45 pm

Updating just a few colum values in a MySQL DB

Post 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?
buckit
Forum Contributor
Posts: 169
Joined: Fri Jan 01, 2010 10:21 am

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

Post 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)?
me!
Forum Contributor
Posts: 133
Joined: Sat Nov 04, 2006 8:45 pm

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

Post 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...
buckit
Forum Contributor
Posts: 169
Joined: Fri Jan 01, 2010 10:21 am

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

Post 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.
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

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

Post 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
me!
Forum Contributor
Posts: 133
Joined: Sat Nov 04, 2006 8:45 pm

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

Post 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!
Post Reply