-2

It says:

Parse error: syntax error, unexpected end of file in C:\xampp\htdocs\trial\register.php on line 104

when I do localhost/trial/register.php line 104 is the line where my html tag closes. I don't know what is going on please help. I'm trying to create a registration page

    session_start();
    //check if logged in
    if (isset($_SESSION['id'])){
        header("Location: index.php");
    }

    if (isset($_POST['register'])){
        include_once("db.php");

        $username = strip_tags($_POST['username']);
        $password = strip_tags($_POST['password']);
        $password_confirm = strip_tags($_POST['password_confirm']);
        $email = strip_tags($_POST['email']);

        $username = stripslashes($username);
        $password = stripslashes($password);
        $password_confirm = stripslashes($password_confirm);
        $email = stripslashes($email);

        $username = mysqli_real_escape_string($db, $username);
        $password = mysqli_real_escape_string($db, $password);
        $password_confirm = mysqli_real_escape_string($db, $password_confirm);
        $email = mysqli_real_escape_string($db, $email);

        //encrypt the password
        $password = md5($password);
        $password_confirm = md5($password_confirm);

        //sql storage queries
        $sql_store = "INSERT into users (username, password, email) VALUES ('$username','$password','$email')";
        $sql_fetch_username = "SELECT username FROM users WHERE username='$username'";
        $sql_fetch_email = "SELECT email FROM users WHERE email='$email'";
        //setting up queries
        $query_username = mysqli_query($db, $sql_fetch_username);
        $query_email = mysqli_query($db, $sql_fetch_email);

        //check for matches, incomplete entry, errors or for email already in use
        if(mysqli_num_rows($query_username)){
            echo"There is already a user with that name!";
            return;
        }

        if($username == ""){
            echo"Please enter a username!";
            return;
        }

        if($password == "" || $password_confirm==""){
            echo"Please enter your password!";
            return;
        }


        if($password !=$password_confirm){
            echo"The passwords do not match!";
            return;
        }


        if (!filter_var($email, FILTER_VALIDATE_EMAIL) || $email ==""){
            echo"This email is not valid!";
            return;
        }

        if (mysqli_num_rows($query_email)){
            echo"That email is already in use!";
            return;
        }

        mysqli_query($db, $sql_store);
        header("Location: index.php");
?> 


<!DOCTYPE html>
<html>
    <head>
        <title>PQ</title>
        <link rel="stylesheet" type="text/css" href="style.css">
        <script src="main.js"></script>
    </head>

    <body>
        <div data-role="page" id="Welcome">
            <div data-role="header">
                <h1>Welcome</h1>                    
            </div>
            <div role="main" id="loginform">
                <form method="post" action="register.php" enctype="multipart/form-data">
                    <input name="username" placeholder="Username" type="text">
                    <input name="password" placeholder="Password" type="password">
                    <input name="password_confirm" placeholder="Confirm Password" type="password">
                    <input name="email" placeholder="Email address" type="text">
                    <input name="register" type="submit" value="Register">
                </form> 
            </div>
            <div data-role="footer" data-position="fixed" data-theme="c">
                <h4>(C) 2016</h4>
            </div>
        </div>  
</body> 
</html>
Thamilhan
  • 13,040
  • 5
  • 37
  • 59
s.purpose
  • 45
  • 1
  • 2
  • 9
  • 1
    You missed a closing bracket `}` of `if (isset($_POST['register'])){` this if condition – Ali Jun 02 '16 at 06:37
  • use `exit` here `header("Location: index.php");exit;` – Niklesh Raut Jun 02 '16 at 06:40
  • It works when I do but when I try to register but I have those set of errors: Warning: include_once(db.php): failed to open stream: No such file or directory in C:\xampp\htdocs\trial\register.php on line 10 Warning: include_once(): Failed opening 'db.php' for inclusion (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\trial\register.php on line 10 Notice: Undefined variable: db in C:\xampp\htdocs\trial\register.php on line 22 – s.purpose Jun 02 '16 at 18:18

1 Answers1

0

This error will display last line only. Because you can close closing brackets in last line also. In your case you didn't close bracket of if(isset($_POST['register'])) As ali said.

Kaja Mydeen
  • 585
  • 1
  • 7
  • 13