1
當我運行下面的代碼我得到這個錯誤:致命錯誤:未捕獲的異常「PDOException」與消息「SQLSTATE [HY093]:無效參數號:沒有參數被束縛
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: no parameters were bound'
<?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;
}
}
?>
當刪除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>
檢查錯誤 –
另外,這個問題看起來像http://stackoverflow.com/q/33087077/ –
的轉貼在哪個查詢中你會得到錯誤?第一次插入?選擇?另一個插入?並且對於測試 – rray