lindm Posted May 6, 2008 Share Posted May 6, 2008 Hoping there is a simple solutions to this. I have a form with around 400 fields. When the form is submitted a php script handles this and updates/inserts the record into a mysql database. Now...is there a simple script to update all fields or must this be handled for every field like: mysql_query("UPDATE tableX SET field1 = '$var', field2 = '$var2' etc.. Thanks Link to comment https://forums.phpfreaks.com/topic/104397-update-all-columns-from-html-post-simple-mysqlphp/ Share on other sites More sharing options...
ILYAS415 Posted May 6, 2008 Share Posted May 6, 2008 I think you'll just have to use mysql_query("UPDATE blablabla Set field1='$var', field3='$var3'"); etc cant thikn of a way to update sooo many fields. Link to comment https://forums.phpfreaks.com/topic/104397-update-all-columns-from-html-post-simple-mysqlphp/#findComment-534438 Share on other sites More sharing options...
nafetski Posted May 6, 2008 Share Posted May 6, 2008 Are the form field names the same as your mysql's tables field names? If so you can do something like... <?php function updateTable($data){ $q = "UPDATE your_table SET "; $num=count($data); $count=0; foreach($data as $key=>$value){ $count++; if($count<$num){ $q .=$key."='".$value."', "; } else{ $q .=$key."='".$value."' "; } $q .="WHERE fieldyouchoose='whatever'"; } ?> Link to comment https://forums.phpfreaks.com/topic/104397-update-all-columns-from-html-post-simple-mysqlphp/#findComment-534719 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.