Jump to content

[SOLVED] Updating multiple values in mySQL db


dmccabe

Recommended Posts

I have a form where the fields are all displayed as editable input boxes with an update button so that the record can be updated.

 

I know how to update a single field:

 

mysql_query("UPDATE `tbl_corpaccount` SET accname = '$_POST['accname']' WHERE aid = '$AID' ");

 

However, how can I update all the fields at the same time?

ok ignore the above message as I figured out I can do:

 

UPDATE table SET field1=`value1`, field2=`value2` WHERE aid = `$aid`
[code]

However I cannot get the syntax right

[code]
$update = "UPDATE `tbl_corpaccount` SET accname=`".$_POST['accname']."`,  WHERE aid = `$aid` ";

 

can some help I keep getting this error:

 

  Quote

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 'WHERE aid = `9`' at line 1

[/code][/code]

Ok managed to get the syntax almost right:

 

$update = "UPDATE `tbl_corpaccount` SET accname = `". htmlspecialchars($_POST['accname']) ."`  WHERE aid = '$aid' ";

 

However I get this as the error now:

 

  Quote

Error: Unknown column 'NCRC Hamiltons' in 'field list'

 

For some reason it thinks the $_POST['accname'] is the column name when in fact that is the value.

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.