1

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:

  1. error_reporting(E_ALL);
  2. 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:

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
  • hi, where have you looked for PHP logging? – suspectus Aug 18 '19 at 12:30
  • oops! If i am honest, nowhere -_- let me find it real quick, im using ubuntu and nginx :) i will post back one mo' :) – Joshua Read Aug 18 '19 at 12:33
  • Your `
    ` tag doesn't have any `method` so by [default](https://stackoverflow.com/questions/2314401/what-is-the-default-form-http-method) it will take `GET` method and your `if($_SERVER["REQUEST_METHOD"] == "POST")` will never be true , just add `method="post"` under your `
    ` tag.
    – Swati Aug 18 '19 at 12:33
  • try `/var/log/nginx/error.log` – suspectus Aug 18 '19 at 12:35
  • I checked logs for the site, there are some but older ones, I corrected those yesterday (was an unexpected end of file, an extra ' } '. But after checking the files on the server are the newest, i re-opened the log file after again attempting the fill in the reg form and store to databse.No new errors have shown up in the log file. – Joshua Read Aug 18 '19 at 12:47
  • omg @Swati how could i be so stupid.... – Joshua Read Aug 18 '19 at 12:47
  • will make the correction and report back aha – Joshua Read Aug 18 '19 at 12:47
  • Warning: mysqli_query() expects at least 2 parameters, 1 given in /www-data/www.estiweb.co.uk/public_html/phplogin/php/validation.php on line 114 Something went wrong. Please try again later. Warning: mysqli_stmt_close() expects parameter 1 to be mysqli_stmt, boolean given in /www-data/www.estiweb.co.uk/public_html/phplogin/php/validation.php on line 139 – Joshua Read Aug 18 '19 at 12:49
  • got this new error let me see if i can solve :) thanks for your help so far guys <3 – Joshua Read Aug 18 '19 at 12:49
  • @JoshuaRead `$sql = mysqli_query("INSERT INTO estiweb_db (username, email, password) VALUES (? ,?, ?)");` This needs TWO parameters, so add `$link` in to your MySQL query as the FIRST parameter. – Martin Aug 18 '19 at 13:07

0 Answers0