【发布时间】:2016-01-11 08:45:58
【问题描述】:
运行以下代码时出现此错误:
致命错误:带有消息的未捕获异常“PDOException” 'SQLSTATE[HY093]: 参数号无效:没有绑定参数'
<?php
include_once("class.user.php");
include('dbconfig.php');
if(isset($_REQUEST["submit"])) {
if (!empty($_GET["title"]) && !empty($_GET["content"]) && !empty($_GET["category"]) && !empty($_GET["price"])) {
$sql = "INSERT INTO project VALUES (NULL, :title, :content, :userid, :price, :category);";
$result = $DB_con->prepare($sql);
$result->bindValue(":title", $_GET["title"]);
$result->bindValue(":content", $_GET["content"]);
$result->bindValue(":userid", $_SESSION["x"]);
$result->bindValue(":price", $_GET["price"]);
$result->bindValue(":category", $_GET["category"]);
$_SESSION['idu'] = $DB_con->lastInsertId();
$sql_pro='select * from project WHERE title=:title';
$result_pro=$DB_con->prepare($sql_pro);
$result_pro->execute();
$row_pro=$result_pro->fetch(PDO::FETCH_ASSOC);
if($result_pro->rowCount() >0 ){
$_SESSION['idu'] = $row_pro['id'];
return true;
}
$sql_upload="INSERT INTO upload VALUES (NULL, :idp , :address);";
$result_up=$DB_con->prepare($sql_upload);
$result_up->bindParam(':address',$_SESSION['upload']);
$result_up->bindParam(':idp',$_SESSION['idu']);
$result_up->execute();
header('location:../single-project.php');
exit;
} else {
header("location:../create.php?error=10");
exit;
}
}
?>
当 remove execute() 函数调用没有错误! 但它不显示标题或任何内容。如何解决?
<?php
include("controller/check-single-project.php");
include("header.html");
?>
<div class="col-sm-6 col-sm-offset-3" style="margin-top: 50px;">
<h1 class="text-right"><?php echo $prosingle_r->pro_single('title'); ?></h1>
<div class="text-right">
<p class="content-txt"><?php echo $prosingle_r->pro_single('content'); ?></p>
</div>
</div>
【问题讨论】:
-
另外,这个问题看起来像是stackoverflow.com/q/33087077的转帖
-
您在哪个查询中得到错误?第一次插入?选择?另一个插入?并用
header(....)注释所有行以进行测试 -
不知道会话是否已经开始。