I made a simple query to update my table using php, but could not figure out the error.
My Function :
function editData($id, $data) {
$message ="";
$query= "UPDATE blood_data SET name='{$data['name']}', group='{$data['group']}',
address1='{$data['address']}', district='{$data['district']}',
age='{$data['age']}', sex='{$data['sex']}', phone='{$data['phone']}',
mobile='{$data['mobile']}', email='{$data['email']}'
WHERE id='{$id}' ";
if(mysql_query($query)) {
$message ="Data Successfully Updated ";
}else {
die("failed: " . mysql_error());
}
return $message;
}
This is what passed in function :
$dataArray = [
'name'=>$_POST['full_name'],
'group'=>$_POST['group'],
'sex'=>$_POST['sex'],
'age'=>$_POST['age'],
'address'=>$_POST['address'],
'district'=>$_POST['district'],
'email'=>$_POST['email'],
'phone'=>$_POST['phone'],
'mobile'=>$_POST['mobile']
];
$msg = editData($idUploader, $dataArray);
And the error message thrown was :
failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'group='O +', address1='dsd', district='sdfs', age='22', sex='male', phone='23423' at line 1