Code: Select all
function Update($fieldName, $value, $tableName, $cond)
{
for($i=0;$i<count($fieldName);$i++)
{
$ins_value.="$fieldName[$i]='$value[$i]', "; //problem occurs here
}
$ins_value=substr($ins_value,0,-2);
if($cond)
$cond="WHERE $cond";
echo "UPDATE $tableName SET $ins_value $cond";
$query_upd=mysql_query("UPDATE $tableName SET $ins_value $cond");
if(query_upd)
return $query_upd;
else
return mysql_error();
}fieldname and values are arrays
It works fine, but if i wanted to update a value by using fieldname it does not work.
for example, if there is a field name called counter and i want to update it by counter=counter+1 it does not work. So i modified the code from
Code: Select all
$ins_value.="$fieldName[$i]='$value[$i]', ";
to
$ins_value.="$fieldName[$i]=$value[$i], ";Can anyone tell me how to solve this?
Thanx