0

我使用以下功能:

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 =”附近使用正确的语法

MemberIDOddjob的 是成员表中的主键。这个想法是每个成员可以在零工表中拥有多个零工。我可能需要做某种加入吗?

另外,如果我尝试在 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 INTOoddjob(DaysAvailable) VALUES (Wednesday )出于某种原因它没有拾取任何其他字段。任何想法为什么?

4

2 回答 2

2

我认为你错过了引号..试试这个

  INSERT INTO `oddjob`(`OddJobName`, `Description`, `DaysAvailable`) VALUES (painter,test,Friday) WHERE `MemberID` = 35

您可以使用更新语句而不是插入 .. 请查看此链接

如何在 MySQL Insert 语句中添加 where 子句?

于 2013-04-09T17:02:20.440 回答
0

我无法理解 Insert 语句中 where 子句的用途。您是否尝试在成员 ID 35 之后插入记录?您不能将条件语句与插入查询一起使用。

只需删除 where 子句,我想它应该对你有用

INSERT INTO `oddjob`(`OddJobName`, `Description`, `DaysAvailable`) VALUES (painter,test,Friday)
于 2013-04-10T08:41:36.483 回答