Im using the following function:
function Add_Oddjob ($Add_Oddjob){
global $MemberID;
$update = array();
array_walk($Add_Oddjob, 'array_sanitize');
foreach($Add_Oddjob as $field=>$data){ //loop through update data in Add_Oddjob.php
$update[] = '`' . $field . '` = \'' . $data . '\'';
}
mysql_query("INSERT INTO `oddjob`($field) VALUES ($data)");
Add_Oddjob.php
if (isset($_POST['OddJobName']) && isset($_POST['Description']) && isset($_POST['DaysAvailable']) && empty($errors) === true){//if (empty($_POST) === false && empty($errors) === true) { //if (isset(empty($_POST['OddJobName'])) && isset(empty($_POST['Description'])) && isset(empty($_POST['DaysAvailable'])) === false && empty($errors) === true)
$daysavailable='';
foreach ($_POST['DaysAvailable'] as $value)
{
$daysavailable .=$value." ";
}
$Add_Oddjob = array (
'MemberID' => $MemberID,
'OddJobName' => $_POST['OddJobName'],
'Description' => $_POST['Description'],
'DaysAvailable' => $daysavailable,
);
Add_Oddjob ($Add_Oddjob);
if(success){
header('Location: member.php?username='.$username);
exit ();
}
} else if (empty($errors) === false){
//otherwise output errors
echo output_errors($errors);
}
But when I log in as a user and enter data 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 'WHERE MemberID
=' at line 1
The MemberID
in the Oddjob
table is a primary key in the Member Table. The idea is that each member can have more than one odd job in the odd job table. Do I need to do some sort of join maybe?
Also If i try the insert query in phpmyadmin:
INSERT INTO `oddjob`(`OddJobName`, `Description`, `DaysAvailable`) VALUES (painter,test,Friday) WHERE `MemberID` = 35
I get this 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` = 35' at line 1
Any help would be great!
EDIT
So I removed the WHERE clause from my query because I didnt realise I couldnt have that in an insert query. Now if i echo the query i see: INSERT INTO
oddjob(DaysAvailable) VALUES (Wednesday )
for some reason its not picking up any of the other fields. Any ideas why?