PHP使用语法插入SQL表错误

时间:2016-11-21 16:31:46

标签: php mysql mysqli

我正在学习如何在MySQLi中使用PHP,并且我在将信息正确插入到我已设置的表中时遇到问题。这是我的代码:

 $temp_category = $_POST['category'];
    $temp_fname = $_POST['recipient-fname'];
    $temp_lname = $_POST['recipient-lname'];
    $temp_email = $_POST['recipient-email'];
    $temp_date = $_POST['award-date']; 
    $auth_userId = $_SESSION['id'];
    $auth_email = $_SESSION['email'];


    $mysqli = mysqli_connect($host, $dbUser, $dbPword, $db, $port);
    if ($mysqli->connect_errno) {
        echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
    }

    $sql = 'INSERT INTO award_entry (award_category,granted_time,authorizing_user_id,authorizing_user_email,fname,lname,recipient_email),
    VALUES ("'.$temp_category.'", "'.$temp_date.'","'.$auth_userId.'", "'.$auth_email.'","'.$temp_fname.'", "'.$temp_lname.'","'.$temp_email.'")';


    if ($mysqli->query($sql) === TRUE) {
        echo "award_entry successfully updated";
    }
    else {
         echo "Error: " . $sql . "<br>" . $mysqli->error;
    }

我一直收到错误你的SQL语法错误了#34;检查与您的MySQL服务器版本相对应的手册,以获得正确的语法,以便在&#39;附近使用。价值观(&#34;员工周刊&#34;,&#34; 2016-11-05&#34;,&#34; 20&#34;,&#34; jenisearaujo@gmail.com",&#34;杰克&#34;,&#39;在第1行&#34;

但我不知道我的代码有什么问题。

1 个答案:

答案 0 :(得分:0)

 $sql = 'INSERT INTO award_entry (award_category,granted_time,authorizing_user_id,authorizing_user_email,fname,lname,recipient_email)***,***
VALUES ("'.$temp_category.'", "'.$temp_date.'","'.$auth_userId.'", "'.$auth_email.'","'.$temp_fname.'", "'.$temp_lname.'","'.$temp_email.'")';

在VALUES

之前的右括号后删除逗号