【发布时间】:2016-02-18 08:49:06
【问题描述】:
这是错误信息:
SQLSTATE[42000]:语法错误或访问冲突:1064 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的“$userID”附近使用正确的语法
这是我的代码:
<?php
require('includes/config.php');
//if logged in redirect to members page
require('layout/header.php');
if (isset($_POST['create'])) {
try {
$userID=$_SESSION['memberID'];
//insert into database with a prepared statement
$stmt = $db->prepare('INSERT INTO business (bus_id,bus_name,bus_description,bus_phone,bus_email,bus_website,bus_category,bus_address,bus_hours,memberID) VALUES (NULL, :name, :description, :phone, :email, :website, :category, :address, :hours), $userID');
$stmt->execute(array(':name' => $_POST['bname'],':description' => $_POST['bdescription'],':phone' => $_POST['bphone'],':email' => $_POST['bemail'],':website' => $_POST['bwebsite'],':category' => $_POST['bcategory'],':address' => $_POST['baddress'],':hours' => $_POST['bhours']));
$id = $db->lastInsertId('bus_id');
//redirect to index page
header('Location: memberpage.php?action=joined');
exit;
}
//else catch the exception and show the error.
catch(PDOException $e) {
$error[] = $e->getMessage();
}
}
?>
【问题讨论】:
-
你设置
bus_id主键了吗 -
你有一个)这里不应该是
:hours) -
您以
:hours), $userID'结束查询,我猜, $userID的部分必须删除
标签: javascript php mysql web-services mysqli