-2

I want to insert some information into a MySQL table but in the line of code where I'm inserting the info, it keeps giving me the same error.

The problem is in the first line of code.

I checked any parentheses I maybe forgot to add or square brackets or curly brackets. I don't see any problems but maybe you will. Could you please help me?

for some reason this if statement doesn't want to be inside the box of code.

if(mysql_num_rows($sql2==1) {

        $sql = "INSERT INTO users (username, email, password) VALUES (:username, :email, :password)";

        if($stmt = $pdo->prepare($sql)){
            // Bind variables to the prepared statement as parameters
            $stmt->bindParam(":username", $param_username, PDO::PARAM_STR);
            $stmt->bindParam(":email", $param_email, PDO::PARAM_STR);
            $stmt->bindParam(":password", $param_password, PDO::PARAM_STR);

            // Set parameters
            $param_username = $username;
            $param_email = $email;
            $param_password = password_hash($password, PASSWORD_DEFAULT); // Creates a password hash

            // Attempt to execute the prepared statement
            if($stmt->execute()){
                // Redirect to login page
                header("location: login.php");
            } else{
                echo "Something went wrong. Please try again later.";
            }
        }

        // Close statement
        unset($stmt);
    }

Parse error: syntax error, unexpected ';'

PM 77-1
  • 12,933
  • 21
  • 68
  • 111
SirPVP
  • 45
  • 5

1 Answers1

1

You have to do it like this:

if (mysql_num_rows($sql2) == 1) {
    //ur code
}

You forgot a ")" and are asking a qustion inside a pdo function

It also give the response of "Parse error: syntax error, unexpected ';' everything looks fine"

because the function mysql_num_rows cant handle "=="

EDIT

the function mysql_num_rows is deprecated use mysqli_num_rows() instead

read the docs here

Nanko Prinzhorn
  • 130
  • 1
  • 2
  • 11