0

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.

Tim
  • 143
  • 9
  • What is in the ENUM? – Timothy Lukas H. Jan 27 '19 at 18:37
  • ENUM("admin", "publisher") @TimothyLukasH. – Tim Jan 27 '19 at 18:37
  • @Tim What are the return values of your `mysqli_prepare()`, `mysqli_stmt_bind_param()` and `mysqli_stmt_execute()` calls? Output them with `var_dump();` and [edit] your question to include the output. Also, include the output of `var_dump(mysqli_error($con));`. – Progman Jan 27 '19 at 18:43
  • @Progman I just noticed something strange. The SQL query above is a function of a class which returns true when successful. In the file where I call the function, nothing will happen when it is successfull. But still it redirects me to the start page. So I will need to fix that first – Tim Jan 27 '19 at 18:50
  • It was something completly diffrent... I didn't redirect my form to register, but rather to the main page. Sorry. – Tim Jan 27 '19 at 18:52
  • Error reporting link for mysqli http://php.net/manual/en/mysqli.error.php – user3783243 Jan 27 '19 at 19:03

1 Answers1

0

Have you tried capitalizing 'insert'? And try changing '$locked = "false";' to'$locked = 0';

Henryk Parker
  • 134
  • 1
  • 6
  • 1
    `insert` doesn't need to be capitalized. That is developers preference. – user3783243 Jan 27 '19 at 18:39
  • as @user3783243 captializing doesn't matter and I've allready tried using 0. Even if I don't bind the zero and write it into the query string it won't work – Tim Jan 27 '19 at 18:41
  • It was something completly diffrent... I didn't redirect my form to register, but rather to the main page. Sorry. – Tim Jan 27 '19 at 18:52