Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP Variable not getting assigned after a successful run
    text
    copied!<p>I've got a script to register a new user into the database, and it works fine - the user does get put into the database. However, the variable $success does not get changed to 1(even though it should be, because the query is successful). Every time I call this function, it returns the value of $success as 0. The only thing I can think of is if the query still runs fine, but returns FALSE. But that wouldn't really make much sense when it is updating the table with the correct information? </p> <pre><code> public function register($email, $password, $firstname, $lastname, $employee_number) { //Lets us know if we registered properly or not $success = 0; //Salt and encrypt the password $salt = generateSalt($password); $encypted_password = generatePassword($salt, $password); if(isset($this-&gt;db)) { if($this-&gt;db-&gt;query("INSERT INTO users (email, encrypted_password, salt, first_name, last_name, employee_number) VALUES('$email', '$encypted_password', '$salt', '$firstname', '$lastname', '$employee_number');")) { $success = 1; } } $arr = array("success" =&gt; $success); return json_encode($arr); } </code></pre> <p>EDIT: I knew I was forgetting to mention something, this is using SQLite3. According to the documentation(<a href="http://www.php.net/manual/en/sqlite3.query.php" rel="nofollow">http://www.php.net/manual/en/sqlite3.query.php</a>), it will return an SQLite3Object if the query returns results. HOWEVER, if it does not return results it should just return TRUE if the query succeeded, or FALSE if the query failed. Double checking the var_dump of the statement, I am getting back NULL. Last I knew, INSERT statements were not supposed to return anything, so this is a bit strange. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload