dmccabe Posted June 23, 2008 Share Posted June 23, 2008 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? Link to comment https://forums.phpfreaks.com/topic/111489-solved-updating-multiple-values-in-mysql-db/ Share on other sites More sharing options...
dmccabe Posted June 23, 2008 Author Share Posted June 23, 2008 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] Link to comment https://forums.phpfreaks.com/topic/111489-solved-updating-multiple-values-in-mysql-db/#findComment-572193 Share on other sites More sharing options...
dmccabe Posted June 23, 2008 Author Share Posted June 23, 2008 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. Link to comment https://forums.phpfreaks.com/topic/111489-solved-updating-multiple-values-in-mysql-db/#findComment-572203 Share on other sites More sharing options...
dmccabe Posted June 23, 2008 Author Share Posted June 23, 2008 lol got it sorted I had ` where I needed ' Link to comment https://forums.phpfreaks.com/topic/111489-solved-updating-multiple-values-in-mysql-db/#findComment-572214 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.