Drummin Posted February 29, 2012 Share Posted February 29, 2012 Did you echo out $sql as was suggested? Quote Link to comment https://forums.phpfreaks.com/topic/257885-any-easy-way-to-list-update-columns/page/3/#findComment-1322458 Share on other sites More sharing options...
batwimp Posted February 29, 2012 Share Posted February 29, 2012 Now that we've established the correct POST variable names, I think you need to add it to the if statement: if ($indexName!="record_id" && $indexName!="action" && $indexName!="submitpass"){ $myUpdateList[] = "$indexName='$value'"; } To remove it from the SQL query. Quote Link to comment https://forums.phpfreaks.com/topic/257885-any-easy-way-to-list-update-columns/page/3/#findComment-1322465 Share on other sites More sharing options...
Drummin Posted February 29, 2012 Share Posted February 29, 2012 Now that we've established the correct POST variable names, I think you need to add it to the if statement: EXACTLY!!!!!!!! So final should be <?php if(isset($_POST['submitpass']) && $_POST['submitpass']=="Submit Order"){ //recieve the variables $roastturkey = $_POST['roastturkey']; $broccoli = $_POST['broccoli']; $brisket = $_POST['brisket']; $carrots = $_POST['carrots']; if(isset($_POST['record_id']) && !empty($_POST['record_id'])){ $record_id=$_POST['record_id']; $myUpdateList = array(); foreach($_POST as $indexName => $value){ if ($indexName!="record_id" && $indexName!="submitpass"){ $value=mysql_real_escape_string($value); $myUpdateList[] = "$indexName='$value'"; }//if ($indexName!="record_id" && $indexName!="action") }//foreach($_POST as $indexName => $value) $fields = implode(",", $myUpdateList); $sql=("UPDATE testtable SET $fields WHERE id=$record_id"); $result=mysql_query($sql); }//if(isset($_POST['record_id']) && !empty($_POST['record_id'])) }//if(isset($_POST['action']) && $_POST['action']=="submitform") ?> We hope... Quote Link to comment https://forums.phpfreaks.com/topic/257885-any-easy-way-to-list-update-columns/page/3/#findComment-1322475 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.