Sunday, 13 November 2016

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

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...