Wednesday, August 28, 2019

mysql - PHP MySQLi doesn't execute INSERT query

I had a false redirect. But the system won't let me delete the question
I have a website with a register page. In the backend is a SQL database, but while UPDATE and SELECT work, INSERT doesn't. IT also doesn't give me any errors.



The code which makes the INSERT statement looks as follows:




$username = "peter";
$pwhash = password_hash($password, PASSWORD_DEFAULT);

$role = "publisher";
$locked = "false";

//Prepare SQL Query
$sql = "insert into user(username, password, role, locked)";
$sql .= " VALUES (?, ?, ?, ?);";


//Reuire SQL Connection
require "db_inc.php";

//Prepare stmt
$stmt = mysqli_prepare($con, $sql);

//Bind Parameters
mysqli_stmt_bind_param($stmt, 'ssss',
$username,
$pwhash,

$role,
$locked);

//Execute SQL
mysqli_stmt_execute($stmt);


mysqli_close($con);



The SQL database looks like this:
SQL Database



What am I doing wrong? The $con connection is correct, as it workes on the SELECT and UPDATE querys.

No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...