I am doing work with php object oriented and mysqli. i have class name Database.php inside this class i have defined a function name update. i did some thing wrong i think that's why it doesn't work fine. when i use to run click at update then data retrieves in Form but when i try to save the updated form it always updated only first column of my database. function code is given below:
public function update($tablename, $value, $where){
$Update = " UPDATE ".$tablename." SET ";
$array_keys = array_keys($value);
$array_values= array_values($value);
$count = count($array_keys);
for($i=0; $i< $count; $i++){
$value[$i] = " = '".$value[$array_keys[$i]]."' ";
}
//$value = implode(" ",$value);
print_r($value);
$Update .= " ".$value." WHERE ".$where;
$Utest = $this->DbCon->query($Update);
if($Utest){
return true;
}else{
return false;
}
here is php code that i have tried before
if(isset($_POST['update'])){
$id1 = $_POST['id'];
$name = $_POST['name'];
$city = $_POST['city'];
$success=$DbQuery->update("record", array(" name " => $name ,"city" => $city)," id =".$id1);
if($success){
header("LOCATION:index.php");
}else{
echo "try again ";
}
}
do you have any good suggestion for update function how ic an improve this function. actually i am new in php object oriented so suggest me easy method to this. Thanks