-1

Hi i am a php newbie and i am currently following a tutorial on how to make an inventory management system and i am still at the login screen. Since i am new to php i don't know much about it. I hope someone expert can help me solve this problem. Here is the code

<?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>

and the error is in this line

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

Any help is appreciated and sorry if the script is kind of mess I am using php 5 by the way Thank you

Lawrence Cherone
  • 41,907
  • 7
  • 51
  • 92

1 Answers1

0

It is a syntax error. You missed a semicolon.

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

      $errors[] = "Username does not exist";
shawn
  • 3,838
  • 11
  • 24