Jump to content

Recommended Posts

Am I missing something in the Foreach statement that is causing the query not to update? I did a standalone test and the query updated, but when I run the code below nothing happens.

  foreach ($_POST[add] as $col => $value) $_POST[add][$col] = strip_tags(stripslashes($value)); {
  mysql_query("UPDATE rate_members SET m_'".$col."'='".sql_escape_string(stripslashes($value))."' WHERE m_id='$m_id'");
}

 

standalone test to make sure the database updates. works fine

  mysql_query("UPDATE rate_members SET m_year='".sql_escape_string(stripslashes($_POST[add][year]))."' WHERE m_id='$m_id'");

Looks like you are making your foreach loop execute only the first statement. Move your opening { back one line:

 

foreach ($_POST[add] as $col => $value) {
   $_POST[add][$col] = strip_tags(stripslashes($value));
   mysql_query("UPDATE rate_members SET m_'".$col."'='".sql_escape_string(stripslashes($value))."' WHERE m_id='$m_id'");
}

Looks like you are making your foreach loop execute only the first statement. Move your opening { back one line:

 

foreach ($_POST[add] as $col => $value) {
   $_POST[add][$col] = strip_tags(stripslashes($value));
   mysql_query("UPDATE rate_members SET m_'".$col."'='".sql_escape_string(stripslashes($value))."' WHERE m_id='$m_id'");
}

 

still not working. I removed everything from the processing php file so its only the foreach & query. the standalone version works fine, but not this coding. I also removed everything from the FORM i just have a month date and year select boxes. so its very basic for the testing yet still not Updating the changes

ok i figured it out with this code. setting the value into a var did the trick and I removed the quotes from around the $col var

 

foreach ($_POST[add] as $col => $value) {
  $_POST[add][$col] = strip_tags(stripslashes($value));
//  mysql_query("UPDATE rate_members SET m_'".$col."'='".sql_escape_string(stripslashes($value))."' WHERE m_id='$m_id'");
echo $col;
$entry = sql_escape_string(stripslashes($value));
echo $entry;
mysql_query("UPDATE rate_members SET m_$col = $entry WHERE m_id=$m_id");
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

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