I'm trying to allow users to update their profiles and im using the following functions to do so:
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();
}
this is the update page.(Relevant code only)
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);
}
?>
When I enter new info for the user I get the following error:
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
when I print out $update
I get:
Array ( [0] => `MemberID` = '30' [1] => `OddJobName` = 'test' [2] => `Description` = 'test' [3] => `DaysAvailable` = 'Friday ' )
Which seems fine so im not sure whats wrong with my query. If I put an update query into phpmyadmin like :
UPDATE `oddjob` SET `OddJobName`= test,`Description`=test,`DaysAvailable`=Friday, WHERE `MemberID` = 30
I get the error
#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
(The MemberID in the oddjob table is a foreign key. MemberID is a primary key in the member table.)
I am not gifted at this SQL stuff...as you can tell, so please help if you can.