So this was previously working using a replace but would a replace empty fields are that not present upon update?
Since moving to the update, the $id is not being read even though it's clearly shown on the statement.
function updateData($table,$id,$data){
$extra = '';
foreach ( $data as $key=>$row )
{
$set[]= $key."='".$row."'";
}
$set = implode(',',$set);
if($id){
$extra = "WHERE `id`='$id'";
}
$statement = "UPDATE `$table` SET ".$set." ". $extra;
print_r($statement);
$this->printDebug('Update Table Data',$statement);
if($stmt = $this->conn->prepare($statement)){
$stmt->execute() or trigger_error($stmt->error, E_USER_ERROR);
$last_id = $stmt->insert_id;
$response = array("message"=>"success","last_id"=>$last_id);
return ($response);
} else {
// die($this->conn->error);
trigger_error($this->conn->error,E_USER_ERROR);
}
}
UPDATE `categories` SET category_status='1',featured='1',category_name='Health & Beauty',parent_id='0',price_low='',price_high='',category_description='',id='1',tags='null',date_added='2022-06-18 22:11:31',last_modified='2022-06-18 22:11:31',meta_type='category',meta_id='0',images='{"path":[""]}'
$insertData = $b->updateData('products',$_POST['id'],$_POST);