1

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'

<?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 ! 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>
4
  • 2
    Plus, this question looks like a repost of stackoverflow.com/q/33087077 Commented Oct 13, 2015 at 14:38
  • In which query do you get the error? first insert? select? the other insert? And comment all lines with header(....) for tests Commented Oct 13, 2015 at 14:42
  • 1
    no idea whether the session's been started or not. Commented Oct 13, 2015 at 14:43
  • Hello, I am facing the same error. May I please know where to find the code you have copied in the question. Commented Feb 23, 2022 at 15:42

1 Answer 1

3

The erro is here, you need bind again :title because is a diferente query

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());
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.