我做了一個簡單的查詢來更新我的表使用PHP,但無法找出錯誤。MySQL更新語法錯誤
我的功能:
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;
}
這是在函數中傳遞:
$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);
而拋出的錯誤信息是:
失敗:你在你的SQL錯誤句法;檢查對應於你的MySQL服務器版本的手冊,以便在'group ='O +',address1 ='dsd',district ='sdfs',age = '22',sex ='male',phone ='23423'at line 1