ユーザーがプロファイルを更新できるようにしようとしていますが、次の関数を使用してそうしています:
function update_user($update_data){
global $session_MemberID;
$update = array();
array_walk($update_data, 'array_sanitize');
foreach($update_data as $field=>$data){ //loop through update data in update_info.php
$update[] = '`' . $field . '` = \'' . $data . '\'';
}
//print_r($update);
//die();
mysql_query("UPDATE `oddjob` SET " . implode(', ', $update). " WHERE `MemberID` = $session_MemberID") or die (mysql_error());
}
if (logged_in() ===true) {
$session_MemberID = $_SESSION['MemberID'];//grabbing value from login
$user_data= user_data($session_MemberID,'MemberID','Name','Address','Postcode','DOB','Mobile','CoinsAvailable','Email','Password','RepeatPassword','OddJobName','Description','DaysAvailable','profile');
exit();
}
更新ページです。(該当コードのみ)
if (isset($_POST['OddJobName']) && isset($_POST['Description']) && isset($_POST['DaysAvailable']) && empty($errors) === true){//if (empty($_POST) === false && empty($errors) === true) {
$daysavailable='';
foreach ($_POST['DaysAvailable'] as $value)
{
$daysavailable .=$value." ";
}
$update_data = array (
'MemberID' => $MemberID,
'OddJobName' => $_POST['OddJobName'],
'Description' => $_POST['Description'],
'DaysAvailable' => $daysavailable,
);
update_user ($update_data);
if(success){
header('Location: member.php?username='.$username);
exit ();
}
} else if (empty($errors) === false){
//otherwise output errors
echo output_errors($errors);
}
?>
ユーザーの新しい情報を入力すると、次のエラーが表示されます。
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 '' at line 1
印刷すると次の$update
ようになります。
Array ( [0] => `MemberID` = '30' [1] => `OddJobName` = 'test' [2] => `Description` = 'test' [3] => `DaysAvailable` = 'Friday ' )
これは問題ないように見えるので、クエリの何が問題なのかわかりません。次のような更新クエリを phpmyadmin に入れると:
UPDATE `oddjob` SET `OddJobName`= test,`Description`=test,`DaysAvailable`=Friday, WHERE `MemberID` = 30
エラーが発生します
#1064 - 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 'WHERE MemberID = 30' at line 1
(oddjob テーブルの MemberID は外部キーです。MemberID は member テーブルの主キーです。)
お分かりのように、私はこの SQL に才能がありません。できれば助けてください。