| | |
updating multiple columns in single MySQL table
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jun 2008
Posts: 46
Reputation:
Solved Threads: 0
hey guys...
i know this is a very common problem and has been posted earlier also... but nobody seems to have figured out a solution...
i am making a program using PHP/MySQL.
I need to update 3 columns in a table. when i use a single UPDATE-SET command(using commas/AND etc etc.... i've tried them all).. only the first field gets updated, the other 2 remaining as they are.
When i use three seperate UPDATE commands, one for each column, FUNNILY, the first and the third columns get updated, and for some GOD KNOWS WHAT reason, the second column just refuses to change...
the code is correct and is infact the same for all 3 statements (with the "field_name" beng different of course..)
please help as this is really bugging...
thx..
i know this is a very common problem and has been posted earlier also... but nobody seems to have figured out a solution...
i am making a program using PHP/MySQL.
I need to update 3 columns in a table. when i use a single UPDATE-SET command(using commas/AND etc etc.... i've tried them all).. only the first field gets updated, the other 2 remaining as they are.
When i use three seperate UPDATE commands, one for each column, FUNNILY, the first and the third columns get updated, and for some GOD KNOWS WHAT reason, the second column just refuses to change...
the code is correct and is infact the same for all 3 statements (with the "field_name" beng different of course..)
please help as this is really bugging...
thx..
•
•
Join Date: Apr 2006
Posts: 66
Reputation:
Solved Threads: 11
Hello,
the update command looks like this:
UPDATE tbl_name SET col1='value1', col2='value2', col3='value3'
WHERE some conditions comes here
the update command looks like this:
UPDATE tbl_name SET col1='value1', col2='value2', col3='value3'
WHERE some conditions comes here
•
•
Join Date: Jun 2008
Posts: 46
Reputation:
Solved Threads: 0
hi silviuks
i tried the method u suggested, but with that, only the first of the 3 columns gets updated.
I tries using 3 diff commands, and this , somehow, causes col 1 and 3 to update, leaving col 2 unchanged.
THE CODE
i tried the method u suggested, but with that, only the first of the 3 columns gets updated.
I tries using 3 diff commands, and this , somehow, causes col 1 and 3 to update, leaving col 2 unchanged.
THE CODE
php Syntax (Toggle Plain Text)
mysql_query("UPDATE client SET dod = '$dod' where ID = '$id' "); mysql_query("UPDATE client SET mod = '$mod' where ID = '$id' "); mysql_query("UPDATE client SET yod = '$yod' where ID = '$id' ");
Last edited by peter_budo; Jul 7th, 2008 at 7:36 am. Reason: Keep It Organized - please use [code] tags
Are you sure all columns are of type string ? We could be of more help if you post the table structure.
Have you tried:
to see if there is an error ?
Have you tried:
PHP Syntax (Toggle Plain Text)
mysql_query(...) or die(mysql_error());
to see if there is an error ?
Last edited by pritaeas; Jul 2nd, 2008 at 2:14 pm.
"If it is NOT source, it is NOT software."
-- NASA
-- NASA
Hello..
Try this code to update three or more fields in database:
I think it will work properly after this...
ShantI
Try this code to update three or more fields in database:
php Syntax (Toggle Plain Text)
$qur= "update `users` set `username`='".$_POST['username']."', `password`='".$_POST['password']."', `name`='".$_POST['name']."', `email`='".$_POST['emailid']."', `phone`='".$_POST['phoneno']."', `country`='".$_POST['country']."', `county`='".$_POST['county']."', `city`='".$_POST['city']."', `pincode`='".$_POST['zip']."', `shipping`='".$_POST['shipping']."', `billing`='".$_POST['billing']."', `organisation`='".$_POST['org']."', `fax`='".$_POST['fax']."' where id=".$_GET['id']; mysql_query( $qur) ;
I think it will work properly after this...
ShantI
Last edited by peter_budo; Jul 7th, 2008 at 7:37 am. Reason: Keep It Organized - please use [code] tags
•
•
Join Date: Jun 2008
Posts: 46
Reputation:
Solved Threads: 0
i have checked the table structure. All three columns i am trying to update are NOT STRINGS BUT INTEGERS (they are storing date, month and year respectively)...
The three columns are identical in every way.
When I issue the commands:
the 1st and the 3rd column get updated, leaving the 2nd unchanged. I know this seems funny, but i'll be really grateful if somebody could point out the error..
thx... cheers...
The three columns are identical in every way.
When I issue the commands:
php Syntax (Toggle Plain Text)
mysql_query("UPDATE client SET dod = '$dod' where ID = '$id' "); mysql_query("UPDATE client SET mod = '$mod' where ID = '$id' "); mysql_query("UPDATE client SET yod = '$yod' where ID = '$id' ");
the 1st and the 3rd column get updated, leaving the 2nd unchanged. I know this seems funny, but i'll be really grateful if somebody could point out the error..
thx... cheers...
Last edited by peter_budo; Jul 7th, 2008 at 7:41 am. Reason: Keep It Organized - please use [code] tags
•
•
•
•
if somebody could point out the error..
php Syntax (Toggle Plain Text)
mysql_query("update client set dod='$dod', mod='$mod',yod='$yod' where id='$id'");
Ignorance is definitely not bliss!
*PM asking for help will be ignored*
*PM asking for help will be ignored*
•
•
Join Date: Jun 2008
Posts: 46
Reputation:
Solved Threads: 0
i tried using a common update command, but when i use it with mysql_error(), it reports the following error:
You have an error in your SQL syntax, check the manual that corresponds to your MySQL server version for the right syntax to use near 'mod = '77' ,yod='8899' where ID =56 at line 1.
Somebody pls help...
You have an error in your SQL syntax, check the manual that corresponds to your MySQL server version for the right syntax to use near 'mod = '77' ,yod='8899' where ID =56 at line 1.
Somebody pls help...
Okay. Do this.
Tell us what it prints.
php Syntax (Toggle Plain Text)
$query = "update client set dod='$dod', mod='$mod',yod='$yod' where id='$id'"; echo $query; mysql_query($query);
Ignorance is definitely not bliss!
*PM asking for help will be ignored*
*PM asking for help will be ignored*
![]() |
Similar Threads
Other Threads in the PHP Forum
- Previous Thread: Help!!!! open source SMS Shopping Project
- Next Thread: update data through dropdown
| Thread Tools | Search this Thread |
apache api array basic beginner binary body broken cache cakephp class cms code computing confirm cron curl customizableitems database date date/time delete display dynamic echo email error file filter folder form forms forum function functions gc_maxlifetime google headmethod howtowriteathesis href htaccess html iframe image include ip javascript joomla limit link list login malfunction memmory memory menu mlm msqli_multi_query multiple mycodeisbad mysql navigation oop parameter parsing paypal pdf php phpmysql query question random recourse recursion regex script search select seo server sessions snippet source space sql static system table thesishelp trouble tutorial update upload url variable video web webdesign xml youtube






