Jump to content

any easy way to list UPDATE columns


phppup

Recommended Posts

  • Replies 52
  • Created
  • Last Reply

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.

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...

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.