Can't Insert Data Into Tables Containing Auto Increment Primary Key Using PHP Prepared Statements
- by Drew
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();