Trying to insert pdo bound parameters into mysql database

Jimmy Long

I'm trying to use a foreach loop to update database with PDO bound parameters. Everything seems to be set as desired, only problem is query doesn't execute and update the database as desired.

try {
    $dbh = new PDO('mysql:host=localhost;dbname=Batik', 'root', 'root');
    $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $table = $_SESSION['table'];
    error_log($table);
    parse_str($_POST['pages'], $pageOrder);
    $query = "UPDATE $table SET `order` = ':key' WHERE `id` = ':value'";
    $STH = $dbh->prepare($query);


    foreach ($pageOrder['page'] as $key =>$value) {
        error_log($key.$value);
        $STH->bindParam(':value', $value);
        $STH->bindParam(':key', $key);
        //error_log(print_r($STH));
        //error_log(var_dump($STH));
        //error_log($STH->debugDumpParams());
        $STH->execute();

    }
} catch (PDOException $exception) {
    echo "There was an error updating your information, please contact James for assistance. "; 
    error_log($exception->getMessage());
  };

There are no more errors outputting to error.log. It simply won't update the database as desired. I have the query working fine with mysql_query, but when switching over to PDO I have lost functionality. Does anybody have any suggestions for further debugging tools?

Barmar

You must not put placeholders in quotes in the SQL. It should be:

$query = "UPDATE $table SET `order` = :key WHERE `id` = :value";

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

PDO Insert writes value of 1 into all fields with bound parameters

From Dev

Insert form value into mysql database with pdo

From Dev

PDO insert into MySQL Database not working with another PDO query

From Dev

PHP PDO dblib parameters not bound

From Dev

Trying to insert into mysql database ignoring blank fields

From Dev

PDO MySQL prepare->execute INSERT INTO not appearing in Database

From Dev

Inserting data to mysql database using PDO with direct insert statement

From Dev

Insert multiple values via PHP PDO into MySQL database

From Dev

Inserting data to mysql database using PDO with direct insert statement

From Dev

Converting MySql Insert To PDO

From Dev

INSERT INTO array with MySQL and PDO

From Dev

PDO insert BindParam mysql

From Dev

MySQL functions as PDO parameters

From Dev

Trying to connect to access database with PDO

From Dev

Trying to insert value to database

From Dev

pdo, insert php object to database

From Dev

PDO data not insert into database no error

From Dev

Insert Object entries into database with PDO

From Dev

PDO database search with multiple parameters

From Dev

ROracle Errors When Trying to Use Bound Parameters

From Dev

ROracle Errors When Trying to Use Bound Parameters

From Dev

mysql pdo trying to set column to value of uuid() returns "Invalid parameter number: number of bound variables does not match number of tokens"

From Dev

Trying to rewrite mysql_* to pdo

From Dev

How to auto-refresh a JTable bound to Mysql database after insert using NetBeans

From Dev

MYSQL Insert Where Not Exists with PDO

From Dev

Using mysql insert with implode in PDO

From Dev

Confirm record INSERT with PDO and MySQL

From Dev

Insert cookies and date pdo mysql

From Dev

Trying to insert data from form with PDO

Related Related

  1. 1

    PDO Insert writes value of 1 into all fields with bound parameters

  2. 2

    Insert form value into mysql database with pdo

  3. 3

    PDO insert into MySQL Database not working with another PDO query

  4. 4

    PHP PDO dblib parameters not bound

  5. 5

    Trying to insert into mysql database ignoring blank fields

  6. 6

    PDO MySQL prepare->execute INSERT INTO not appearing in Database

  7. 7

    Inserting data to mysql database using PDO with direct insert statement

  8. 8

    Insert multiple values via PHP PDO into MySQL database

  9. 9

    Inserting data to mysql database using PDO with direct insert statement

  10. 10

    Converting MySql Insert To PDO

  11. 11

    INSERT INTO array with MySQL and PDO

  12. 12

    PDO insert BindParam mysql

  13. 13

    MySQL functions as PDO parameters

  14. 14

    Trying to connect to access database with PDO

  15. 15

    Trying to insert value to database

  16. 16

    pdo, insert php object to database

  17. 17

    PDO data not insert into database no error

  18. 18

    Insert Object entries into database with PDO

  19. 19

    PDO database search with multiple parameters

  20. 20

    ROracle Errors When Trying to Use Bound Parameters

  21. 21

    ROracle Errors When Trying to Use Bound Parameters

  22. 22

    mysql pdo trying to set column to value of uuid() returns "Invalid parameter number: number of bound variables does not match number of tokens"

  23. 23

    Trying to rewrite mysql_* to pdo

  24. 24

    How to auto-refresh a JTable bound to Mysql database after insert using NetBeans

  25. 25

    MYSQL Insert Where Not Exists with PDO

  26. 26

    Using mysql insert with implode in PDO

  27. 27

    Confirm record INSERT with PDO and MySQL

  28. 28

    Insert cookies and date pdo mysql

  29. 29

    Trying to insert data from form with PDO

HotTag

Archive