Can't Insert Data Into Tables Containing Auto Increment Primary Key Using PHP Prepared Statements

Posted by Drew on Stack Overflow See other posts from Stack Overflow or by Drew
Published on 2009-11-02T15:22:01Z Indexed on 2010/05/02 16:17 UTC
Read the original article Hit count: 241

Filed under:
|
|

I know I have that my connection to the database works, and a test I did using no auto-increment id worked fine for me. The code below refuses to work and I can't find a a way around it. My table has 3 columns, ID (auto increment), name and value. What do I need to change in order to get this to work?

Thanks in advance

//create placeholder query $query = "INSERT INTO prepared_test (name, value) VALUES (?,?)";

//prepare the query $stmt = mysqli_prepare($connection, $query);

$name = 'steve'; $value = 45;

mysqli_bind_param($stmt, array(MYSQLI_BIND_STRING, MYSQLI_BIND_INT), $name, $value); mysqli_execute($stmt);

if(mysqli_stmt_affected_rows($stmt) != 1) die("issues");

mysqli_stmt_close($stmt);

$connection->close();

© Stack Overflow or respective owner

Related posts about php

Related posts about prepared-statement