-1

My PHP and MySQL knowledge is very little. I am trying to create a very basic login script however when I attempt to submit the credentials, I am faced with an error message that says "this page isn't working, localhost is unable to handle this request.".

Here is my signin.php script

<?php 
session_start();
 require('connect.php');

if (isset($_POST['username']) and isset($_POST['password'])){

$username = $_POST['username'];
$password = $_POST['password'];

$sql = "SELECT * FROM users WHERE username = '$username' and password= '$password'";
 $query = mysqli_query($sql);
if(mysqli_num_rows($query) > 0)
{
  $_SESSION['username'] = $username;
  $_SESSION['password'] = $password;
  header("Location: welcome.html");
  exit();
 }else {
   echo "Error: the information is not correct.";
 }
?>

and this is my html

<!DOCTYPE html>
<html>
<head>
    <title>Murdoch Study Assist</title>
    <link rel="stylesheet" type="text/css" href="style.css">
    <link href="https://fonts.googleapis.com/css?family=Baloo+Chettan" rel="stylesheet">
</head>
<body>
    <div id="login">
        <form method="post" action="signin.php">
        <b>Login</b><br>
        <br>
        <input type="text" name="username" class="input" placeholder="Username"><br><br>
        <input type="password" name="password" class="input" placeholder="Password"><br><br>
        <input type="submit" name="submit" value="Sign In" class="sub"><input type="reset" name="reset" value="Clear" class="res"><br><br><hr><br>
        <h3>Not a member?</h3>
        <button><a href="signup.html">Sign Up</a></button>
        </form>
    </div>
</body>
</html>
  • https://stackoverflow.com/questions/40216761/the-localhost-page-isn-t-working-localhost-is-currently-unable-to-handle-this-re – Carl Binalla Mar 20 '19 at 07:12
  • Possible duplicate of [The localhost page isn’t working localhost is currently unable to handle this request. HTTP ERROR 500](https://stackoverflow.com/questions/40216761/the-localhost-page-isn-t-working-localhost-is-currently-unable-to-handle-this-re) – Haem Mar 20 '19 at 07:19
  • change `mysqli_num_rows` to `mysqli_fetch_array` – xmaster Mar 20 '19 at 07:39

2 Answers2

2

You didn't close below if-statement :

if (isset($_POST['username']) and isset($_POST['password'])){

}//add this in the end
Swati
  • 28,069
  • 4
  • 21
  • 41
  • That did something... now when I execute it, I am redirected to a page that has the PHP logo and a bunch of info about php?? – Riley White Mar 20 '19 at 10:49
  • does any error occur? Also welcome.html exist or not ? does your php working or not? ,edit your post with the problem currently faced . – Swati Mar 20 '19 at 12:06
0

try this

  <?php 
    session_start();
     require('connect.php');

    if (isset($_POST['username']) and isset($_POST['password'])){

    $username = $_POST['username'];
    $password = $_POST['password'];

    $sql = "SELECT * FROM users WHERE username = '$username' and password= '$password'";
     $query = mysqli_query($sql);
    if(mysqli_num_rows($query) > 0)
    {
      $_SESSION['username'] = $username;
      $_SESSION['password'] = $password;
      header("Location: welcome.html");
      exit();
     }else {
       echo "Error: the information is not correct.";
     }
    }// add this tag
    ?>
kealaxshan
  • 338
  • 2
  • 14