如何在第28行的C:\ xampp \ htdocs \“test \ stock_system \ index.php”中解决“解析错误:语法错误,意外'$ errors'(T_VARIABLE)”?

时间:2018-04-16 08:45:55

标签: php html

您好我是一个php新手,我目前正在关注如何制作库存管理系统的教程,我仍在登录界面。因为我是php的新手,所以我不太了解它。我希望有专家可以帮我解决这个问题。这是代码

<?php

require_once 'php-action/db_connect.php';

session_start();

$errors = array();

if($_POST) {
    $username = $_POST['username'];
    $password = $_POST['password'];

    if(empty($usernmame) || empty($password)){
        if($username == ""){
            $error[] = "Username is required";
        }

    if($password = ""){
            $error[] = "Password is required";
    }
  }else {
      $sql = "SELECT * FROM users WHERE username = '$username'";
      $result = $connect->query($sql);

      if($result->num_rows == 1){
          $password = md5($password)

          $errors[] = "Username does not exist";
          // exits
          $mainsql = "SELECT * FROM users WHERE username = '$username' AND 
password ='$password";
          $mainResult = $connect->query($mainSql);

          if($mainResult->num_rows == 1){
              $value = $mainResult->fetch_assoc();
              $user_id = $value['user_id'];
            //set session 
            $_SESSION['user_id'] = $user_id;


   header('location:http://localhost/test/stock_system/dashboard.php');
          }  else{
              $errors[] = "incorrect username/password combination";

          }
          }else{
              $errors[] = "Username does not exist";
          }


  } 



}

?>

<!DOCTYPE html>
<html>
<head>
</head>
    <title>SGU Stock Management System</title>
    <!-- bootstrap -->
    <link rel="stylesheet" type="text/css" 
href="assets/bootstrap/css/bootstrap.min.css">
    <!-- bootstrap theme -->
    <link rel="stylesheet" type="text/css" href="assets/bootstrap/css/bootstrap-theme.min.css">
    <!-- font awesome css -->
    <link rel="stylesheet" type="text/css" href="assets/font-awesome/web-fonts-with-css/css/fontawesome.min.css">
    <!-- custom css -->
    <link rel="stylesheet" type="text/css" href="custom/css/custom.css">
    <!-- jquery -->
    <script type="text/javasript" src="assets/jquery/jquery.min.js"></script>
    <!-- jqueryui -->
    <link rel="stylesheet" type="text/css" href="assets/jquery-ui/jquery.min.css">
    <script type="text/javasript" src="assets/jquery-ui/jquery-ui.min.js"> 
</script>
    <!-- bootstrap js -->
    <script type="text/javasript" src="assets/bootstrap/js/bootstrap.min.js"></script>

<body>

    <div class="container">
     <div class="row vertical"> 
      <div class="col-md-5 col-md-offset-4"> 
       <div class="alert alert-primary" role="alert">
        <h3 class="card-title">Please Sign In</h3> 
         </div>


    <div class="messages">

    <?php if($errors) {
        foreach ($errors as $key -> $value){
            echo'<div class="alert alert-warning" role="alert">
            <i class="glyphicon glyphicon-exclamation-sign"></i>
            '.$value.'</div>';
    }


    }?>


    </div>

<div class="card">
 <div class="card-body">        
    <form class="form-horizontal" action="<?php echo $_SERVER['PHP_SELF']   
  ?>" method="" id="loginform">
    <div class="form-group">
        <label for="username">Username</label>
        <input type="email" class="form-control" id="username" 
  name="username" placeholder="Enter username">
        <small id="emailHelp" class="form-text text-muted">We'll never share your username with anyone else.</small>
    </div>
    <div class="form-group">
        <label for="password">Password</label>
        <input type="password" class="form-control" id="password" placeholder="password">
    </div>
    <div class="form-check">
        <input type="checkbox" class="form-check-input" id="exampleCheck1">
        <label class="form-check-label" for="exampleCheck1">Check me 
out</label>
        </div>
    <button type="submit" class="btn btn-primary">Sign In</button>
    </form>
 </div>     
</div>



</body>
</html>

,错误在此行

$errors[] = "Username does not exist";

如果脚本有点混乱,任何帮助都表示赞赏和抱歉 我顺便使用php 5 谢谢

1 个答案:

答案 0 :(得分:0)

这是语法错误。你错过了一个分号。

      $password = md5($password)  <---  You missed a semicolon here

      $errors[] = "Username does not exist";