Jump to content

any easy way to list UPDATE columns


phppup
 Share

Recommended Posts

  • Replies 52
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share


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