我使用以下功能:
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);
}
但是当我以用户身份登录并输入数据时,我收到以下错误:
您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以MemberID
在第 1 行的“WHERE =”附近使用正确的语法
表MemberID
中Oddjob
的 是成员表中的主键。这个想法是每个成员可以在零工表中拥有多个零工。我可能需要做某种加入吗?
另外,如果我尝试在 phpmyadmin 中插入查询:
INSERT INTO `oddjob`(`OddJobName`, `Description`, `DaysAvailable`) VALUES (painter,test,Friday) WHERE `MemberID` = 35
我收到此错误:
#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
任何帮助都会很棒!
编辑
所以我从查询中删除了 WHERE 子句,因为我没有意识到我不能在插入查询中使用它。现在,如果我回显我看到的查询:INSERT INTO
oddjob(DaysAvailable) VALUES (Wednesday )
出于某种原因它没有拾取任何其他字段。任何想法为什么?