0

I am getting the following possible syntax error within my code Parse error: syntax error, unexpected ';' in C:\xampp\htdocs\Wonderland-Market\index.php on line 13

If you all could help me proofread it for any mistakes I have made I would be very grateful. I followed a tutorial from youtube not sure if the guy made these errors or if I did Please review and let me know what you think may cause more errors. ...

<?php
session_start();
$host = "localhost";
$username="root";
$database="wonderland-db";
$message="";
try{
    $connection = new PDO("mysql:host=$host; dbname=$database", $username,$password);
    $connect->setAttribute(PDO::ERRMODE, PDO::ERRMODE_EXCEPTION);
    if(isset($_POST["login"]))
    {
        if(empty($_POST["username"])  || empty($_POST["password"]))
        $message = '<label>ALL field is required</label'>;
    
    else{
        $query = "SELECT * FROM users WHERE username = :username AND password = :password";
        $statement = $connect->prepare($query);
        $statement->execute(
                              array(
                                  'username' => $_POST["username"]
                                  'password' => $_POST["password"]
                              )
                              );
                              $count =$statement->rowCount(); 
                              if($count > 0)
                              {
                                 $_SESSION["username"] = $_POST["username"];
                                 header(location:"welcome.php");

                              }
                              else
                              {
                                  $message = '<label> Username or Password is wrong </label>'
                              }
            }
         }                  
    }
       catch(PDOException $error)
       {
           $message = $error -> getMessage()
       }
?>



 
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Login</title>
<style>
.login{
width:360px;
margin:50px auto;
font:Cambria, "Hoefler Text", "Liberation Serif", Times, "Times New Roman", serif;
border-radius:10px;
border:2px solid #ccc;
padding:10px 40px 25px;
margin-top:70px; 
}
input[type=text], input[type=password]{
width:99%;
padding:10px;
margin-top:8px;
border:1px solid #ccc;
padding-left:5px;
font-size:16px;
font-family:Cambria, "Hoefler Text", "Liberation Serif", Times, "Times New Roman", serif; 
}
input[type=submit]{
width:100%;
background-color:#009;
color:#fff;
border:2px solid #06F;
padding:10px;
font-size:20px;
cursor:pointer;
border-radius:5px;
margin-bottom:15px; 
}
</style>
</head>
<body>
<div class="login">
<h1 align="center">Login</h1>
<form action="" method="post" style="text-align:center;">
<input type="text" placeholder="Username" id="user" name="user"><br/><br/>
<input type="password" placeholder="Password" id="pass" name="pass"><br/><br/>
<input type="submit" value="Login" name="submit">
<!-- Error Message -->
<span><?php echo $error; ?></span>
</body>
</html>

...

  • 1
    You misplaced a quote a the end of `$message = ';`. – KIKO Software Oct 28 '21 at 11:08
  • Think I corrected it but now I get this error Parse error: syntax error, unexpected ''password'' (T_CONSTANT_ENCAPSED_STRING), expecting ')' in C:\xampp\htdocs\Wonderland-Market\index.php on line 21 – Jesse Garcia Oct 28 '21 at 11:15
  • 1
    You're missing a comma after `$_POST["username"]`. These are very basic syntax errors. For more help see: [PHP parse/syntax errors; and how to solve them](https://stackoverflow.com/questions/18050071/php-parse-syntax-errors-and-how-to-solve-them). – KIKO Software Oct 28 '21 at 11:32
  • Before you ask another one: `$message = ''` is missing an ending `;` – brombeer Oct 28 '21 at 11:33
  • Don't store plain text passwords. PHP has password_hash() and password_verify() – brombeer Oct 28 '21 at 11:34
  • `$connection = new PDO("mysql:host=$host; dbname=$database", $username,$password);` Here, `$password` is not set anywhere – brombeer Oct 28 '21 at 11:35
  • `if(isset($_POST["login"]))` will never trigger, you don't have an input element with that name – brombeer Oct 28 '21 at 11:36

1 Answers1

0

Check below lines:

$message = '<label>ALL field is required</label>';
$message = '<label> Username or Password is wrong </label>';
  • Questions that are about basic PHP syntax errors should not be answered. They should be closed as a duplicate of [PHP Parse/Syntax Errors; and How to solve them?](//stackoverflow.com/questions/18050071) only. If you want to point out their mistake, just post a comment. See: [Should one advise on off topic questions?](//meta.stackoverflow.com/q/276572/1768232). Off-topic questions can be closed and deleted, which could nullify your contribution anyway. – John Conde Oct 28 '21 at 12:11