Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8512267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:13:58+00:00 2026-06-11T04:13:58+00:00

i have a pdo block for inserting values into my table as follows try{

  • 0

i have a pdo block for inserting values into my table as follows

try{

        $user = 'root';
        $pass = null;
        $pdo = new PDO('mysql:host=localhost; dbname=divebay', $user, $pass);

        $name = $_POST['name'];
        $desc = $_POST['description'];
        $cond = $_POST['condGroup'];
        $sprice = $_POST['sprice'];
        $iprice = $_POST['iprice'];
        $incprice = $_POST['incprice']; 
        $duration = $_POST['duration'];
        $img = $_POST['img'];


        $owner = $_SESSION['username'];

        $valid = "set";
        $stmt2 = $pdo->prepare("SELECT * FROM auction WHERE ID = :id");
        $stmt2->bindParam(":id", $random, PDO::PARAM_INT);
        while(isset($valid)){
            $random = rand(100000,999999);
            $stmt2->execute();

            if(!$stmt2->fetch(PDO::FETCH_ASSOC)){
                unset($valid);
            }
        }

        $timestamp = time() + ($duration * 24 * 60 * 60);

        $stmt = $pdo->prepare("INSERT INTO auction(ID, name, owner, holder, sprice, iprice, incprice, etime, img, condition, description)
                      VALUES (:id, :name, :owner, :holder, :sprice, :iprice, :incprice:, :etime, :img, :condition, :description");
        $stmt->bindParam(':id', $random, PDO::PARAM_INT);
        $stmt->bindParam(':name', $name, PDO::PARAM_STR);
        $stmt->bindParam(':owner', $owner, PDO::PARAM_STR);
        $stmt->bindParam(':holder', $owner, PDO::PARAM_STR);
        $stmt->bindParam(':iprice', $iprice, PDO::PARAM_STR);
        $stmt->bindParam(':sprice', $sprice, PDO::PARAM_STR);
        $stmt->bindParam(':incprice', $incprice, PDO::PARAM_STR);
        $stmt->bindParam(':etime', $timestamp, PDO::PARAM_INT);
        $stmt->bindParam(':img', $img, PDO::PARAM_STR);
        $stmt->bindParam(':condition', $condition, PDO::PARAM_STR);
        $stmt->bindParam(':description', $description, PDO::PARAM_STR);
        if($stmt->execute()){
            $worked ="yes";
        }

}catch(PDOException $e){
        echo $e->getMessage();
}

i cant tell why this statement wont execute, the $worked variable has not been set when it is the script is run. all database column names and datatypes have been checked correct as they are. ive never had a problem with a statement not executing until now. whats wrong? how do i go about debugging this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T04:14:00+00:00Added an answer on June 11, 2026 at 4:14 am

    If you setup the database connection with error mode exception PDO will throw an exception if something is wrong with your statement. I also see that you are using the MySQL driver for PDO. If you do this you should always disable emulated prepared statements. So I would write you connection as following (note that I have also set the encoding):

    $pdo = new PDO('mysql:host=localhost; dbname=divebay;charset=utf8', $user, $pass);
    $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    

    Also see this post for more information about this.

    Once you have done this you will see that your statement is wrong. You have one missing ) at the end of the statement:

    $stmt = $pdo->prepare("INSERT INTO auction(ID, name, owner, holder, sprice, iprice, incprice, etime, img, condition, description)
                           VALUES (:id, :name, :owner, :holder, :sprice, :iprice, :incprice:, :etime, :img, :condition, :description)");
                                                                                                                                    ^
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following relevant code: try { self::$db = new PDO($dsn, self::USER, SELF::PASS);
I have a class with this in self::$DB = new PDO(mysql:dbname=$dbname;host:=127.0.0.1 , 'root' ,
I have following code for inserting data into database using PDO. It inserts data
I have my input placed into mySQL through a PDO prepared statement, and have
I have the following code: $link = new PDO(mysql:dbname=$databasename;host=127.0.0.1,$username,$password); $query = $link->prepare(SELECT * FROM
I am switching from plain mysql in php to PDO and I have noticed
What is a decent way to handle PDO error when using try catch block?
I have a PDO Database Class, I'm a little new to PDO so I
I have a PDO prepared statement which looks like this: $STH = $DBH->(CREATE TABLE
I have this old-style non-PDO MySQL query (the code isn't tightened up, just to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.