我使用以下功能:
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服务器版本对应的手册,以便在第1行的'WHERE MemberID
='附近使用正确的语法
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 )
由于某种原因它没有拾取任何其他字段。有什么想法吗?
答案 0 :(得分:2)
我认为你错过了引号..试试这个
INSERT INTO `oddjob`(`OddJobName`, `Description`, `DaysAvailable`) VALUES (painter,test,Friday) WHERE `MemberID` = 35
你可以使用update语句而不是insert ..请看看这个链接
答案 1 :(得分:0)
我无法理解Insert语句中where子句的用法。您是否尝试在会员ID 35之后插入记录?您不能将条件语句与插入查询一起使用。
只需删除where子句,我猜它应该适用于你
INSERT INTO `oddjob`(`OddJobName`, `Description`, `DaysAvailable`) VALUES (painter,test,Friday)