Can someone explain to me why this is not working. Trying to convert into prepared statements in accordance with the advice of everyone, but get stuck right at the beginning ... the connection is fine and it does not return a message, but there is no (in my table called nametable)
<?php $dbhost = "localhost"; $dbuser = "root"; $dbpass = "fidelio"; $dbname = "test"; $con = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname); if(mysqli_connect_errno()) { die("Database connection failed: " . mysqli_connect_error() . " (" . mysqli_connect_errno() . ")"); } $query = "INSERT INTO nametable (fname, lname) values (?,?)"; $stmt = mysqli_prepare($con, $query); $firstName = "simon"; $lastName = "morris"; mysqli_stmt_bind_param($stmt,"ss",$firstname, $lastname); mysqli_stmt_execute($stmt); printf("Error: %s.\n", $stmt->error); $stmt->close(); ?>
I added the last 2 lines and the error returned
Error:.
This works fine, but prepared statements are not ... does anyone know why?
$sql="INSERT INTO nametable (fname, lname) VALUES ('$firstName', '$lastName')"; if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); }
source share