Forum Moderators: coopster
I'm trying to figure out a way to implement the following:
if ($_POST) {
reset ($_POST);
list($key, $val) = each($_POST);
}
$x=0;
while {$key[$x]) {
$result = mysql_query("UPDATE ".$tablename." SET column2=".$val[$x]." where uid=".$key[$x].";", $db) or die("Invalid query: " . mysql_error());
$x++;
}
Obviously $key and $val are not arrays so this doesn't work. Any ideas on how to enumerate $key and $val or split $_POST into two arrays would be appreciated.
Thanks.
what about
foreach ($_POST as $k => $v) {
$result = mysql_query("UPDATE ".$tablename." SET column2=".$v." where uid=".$k, $db) or die("Invalid query: " . mysql_error());
}
you also don't need the semi colon when you pass the query and if $v or $k are strings you will need to put single quotes around them ;)
you also don't need the semi colon when you pass the query
The query string should not end with a semicolon. [us3.php.net]
In case anyone else might find this useful, I've used the following:
foreach ($_POST as $k => $v) {
if ($k!=$v) {
$result = mysql_query("UPDATE ".$tablename." SET column2=\"".$v."\" where uid=".$k, $db) or die("Invalid query: " . mysql_error());
}
}
Adding the if statement removes the Submit:Submit name value pair that gets posted with the rest of the data.
Once again...thanks for the help.