I'm trying to create a simple registration form with PHP, storing the user data in a database after processing the form etc. But the PHP code will not work, but not display any errors either. I have turned on error reporting in the php.ini file and also have included:
error_reporting(E_ALL);
ini_set("display_errors", 1);
at the top of all used php files. I have a feeling that it has something to do with my MySQLi statements. The most likely lines for error are here:if($_SERVER["REQUEST_METHOD"] == "POST"){ // Validate username if(empty(trim($_POST["username"]))){ $username_err = "Please enter a username."; } else{ require_once "db_conn.php"; // Prepare a select statement $sql = "SELECT id FROM estiweb_db WHERE username = ?"; if($stmt = mysqli_prepare($link, $sql)){ // Bind variables to the prepared statement as parameters mysqli_stmt_bind_param($stmt, "s", $param_username); // Set parameters $param_username = trim($_POST["username"]); // Attempt to execute the prepared statement if(mysqli_stmt_execute($stmt)){ // store result mysqli_stmt_store_result($stmt); if(mysqli_stmt_num_rows($stmt) == 1){ $username_err = "This username is already taken."; } else{ $username = trim($_POST["username"]); } } else{ echo "Oops! Something went wrong. Please try again later."; } } // Close statement mysqli_stmt_close($stmt); }
There are a few blocks of code similar to this to validate the other fields in register.php
.
I have tried already to change the way the code is constructed, different processing order. Also I have tried to change the MySQLi to MySQL (I would prefer not to but it was worth a shot).
I have copied my files into a pastebin, I know I should just use small bits but I am unsure exactly where the problem is originating from. Would appreciate anyone who looks over this and can see anything wrong.
The links are:
register.php
: https://pastebin.com/PwfgCby5validation.php
: https://pastebin.com/sbr2DEHKdb_conn.php
: https://pastebin.com/j14d8RWw