//Successful connection to $db
function insert_users($db, $username, $password, $email)
{
echo "FUNCTION CALLED"; //This is outputted successfully
$query = "INSERT INTO `users` (`id`, `username`, `password`, `email`) VALUES ('', ?, ?, ?)";
$stmt = mysqli_stmt_init($db);
if(mysqli_stmt_prepare($stmt, $query))
{
echo "QUERY PREPARED"; // rest of code was snipped (will put up upon request)
} else {
echo "QUERY DENIED"; //This is outputted successfully
}
}
//The $user $pass and $mail are defined and then the function is called
insert_users($db, $user, $pass, $mail);
Database structure:
testdb (database)
-> users (table)
-> id //Primary key, unique key
-> username //unique key
-> password
-> email
Why doens’t the query go through with it’s operation?
It echoes “Query denied” instead of “Query prepared”. The query is invalid I believe. If more information is required, ill be happy to edit this question
EDIT
I added
mysqli_stmt_error($stmt);after the echo "QUERY DENIED";
nothing happens…
EDIT 2
$server = 'localhost';
$user = 'root';
$password = '';
$databse = 'testdb';
$db = @mysqli_connect($server, $user, $password, $database) or die("Could not connect to Database server. Please inform an administrator");
That’s my database setup. Do i put the variables in quotes?
If
idis an auto_increment column, you can just drop it from your insertYou have a typo in
$databse = 'testdb';. Rename it to$database.