Sunday 9 June 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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...