I want to be able to perform an update using values from a form.
I know I need to use some sort of loop, and have indeed used such a method to perform looped inserts thus:
However updates as you know are slightly different in that the value follows immediately after the fieldname declaration in the SQL query thus:
"UPDATE <table> SET <fieldnames> = '<form_values>' WHERE X=Y";
I have established therefore that by using two arrays : one for the fields names
and the other for their respective values:
<?php
include("include/session.php");
$sql = 0;
$sql1 = 0;
$sql2 = 0;
$sql3 = 0;
$table = "qualityuser";
$username = $_SESSION['username'];
include("connect.php");
$sql1 = "UPDATE $table SET ";
$i=0;
foreach($HTTP_GET_VARS as $key=>$val) {
$fieldname[$i] = $key;
$values[$i] = $val;
$sql2 .= $fieldname[$i] . "=" . "'" . $values[$i] . "'" . ",";
$sql3 = substr($sql2,0,-1);
$i++;
}//----end foreach
$sql = $sql1 . $sql3 . " WHERE username='$username'";
echo $sq11;
echo $sq12;
echo $sq13;
mysql_query($sql, $connection) or die(mysql_error());
?>
My efforts though result in an undefined variable error message for $sql1, $sql2, and $sql3.
Can anyone suggest a way of employing, such loop to construct the required UPDATE query??