简体   繁体   English

致命错误:带有消息'SQLSTATE [HY093]的未捕获异常'PDOException':参数号无效:没有参数被绑定

[英]Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: no parameters were bound

I get this error when I run the code below: 我运行以下代码时出现此错误:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: no parameters were bound' 致命错误:未捕获异常'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;
    }
}


?>

When remove execute() function call there is no error ! 删除execute()函数调用时没有错误! but it does not show title or any content .How can this be fixed? 但它没有显示标题或任何内容。如何修复?

<?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>

The erro is here, you need bind again :title because is a diferente query 错误就在这里,你需要再次绑定:title因为是一个不同的查询

change : 改变:

$sql_pro='select * from project WHERE title = :title';
$result_pro=$DB_con->prepare($sql_pro); <-- where is the bind?
$result_pro->execute();

To: 至:

$sql_pro = 'select * from project WHERE title = :title';
$result_pro = $DB_con->prepare($sql_pro);
$result_prod->bindValue(':title', $_GET['title']);
$result_pro->execute();

Or 要么

$result_pro = $DB_con->prepare($sql_pro);
if(!$result_pro->execute(array(':title' => $_GET['title']))){
   print_r($result_pro->errorInfo());
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 致命错误:消息中出现“ SQLSTATE [HY093]:无效的参数编号:未定义参数”的未捕获异常“ PDOException” - Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: parameter was not defined' in PHP致命错误:消息为&#39;SQLSTATE [HY093]的未捕获异常&#39;PDOException&#39;:无效的参数编号: - PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: 未捕获的 PDOException:SQLSTATE[HY093]:无效的参数号:没有绑定参数 - Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: no parameters were bound in 绑定参数错误:致命错误:未捕获的 PDOException:SQLSTATE[HY093]:无效的参数号:未定义参数 - Binding parameters error:Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in 致命错误:未捕获的异常 &#39;PDOException&#39; 带有消息 &#39;SQLSTATE[HY093]:参数无效 - Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter 致命错误:未捕获的 PDOException:SQLSTATE[HY093]:无效的参数号:无参数 - Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: no parameters 致命错误:未捕获的PDOException:SQLSTATE [HY093]:无效的参数编号:混合的命名和位置参数位于 - Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: mixed named and positional parameters in PHP PDO SQL错误:带有消息&#39;SQLSTATE [HY093]的未捕获异常&#39;PDOException&#39;:参数号无效 - PHP PDO SQL error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number 异常信息:消息:SQLSTATE [HY093]:无效的参数号:未绑定任何参数 - Exception information: Message: SQLSTATE[HY093]: Invalid parameter number: no parameters were bound php 错误:致命错误:未捕获 PDOException:SQLSTATE[HY093]:无效参数号:绑定变量数与令牌数不匹配 - php error : Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM