Question: I'm trying to stay on the same page after submitting a form button.
Depending on the button the user clicks, I want to display certain information on that same page the button was clicked.

For some reason it keeps redirecting me back to my "ask\_login.php" page after I click on the button.
I've read around and some people recommend using AJAX or JQuery but I don't really understand much about it. I'd be appreciated if I could get some help. Thanks.

**loggedin.php**

```
   <?php
    $username = $_POST['username'];
    $password = $_POST['password'];

    if($username && $password) {
        //info is provided
        $queryget = mysql_query("SELECT * FROM users WHERE id='$username' AND password='$password'");
            $numrows = mysql_num_rows($queryget);

            if($numrows != 0) {

                //something has been found
                $_SESSION['id'] = $username;

            } else {
                echo "Wrong username/password";
                echo "<script>alert('Username/Password are wrong');</script>";
                echo "<script language='javascript'>window.location = 'ask_login.php';</script>";
            }
    }
    else {
        echo "Wrong username/password";
        echo "<script>alert('Username/Password are wrong');</script>";
        echo "<script language='javascript'>window.location = 'ask_login.php';</script>";
    }

    ?>

              <form method="POST" action="">
              <input type="submit" name="details" value="Details">
              </form>

                <form method="POST" action="">
            <input type="submit" name="optionB" value="option B">
                </form>

            <form method="POST" action="">
            <input type="submit" name="optionC" value="option C">
                </form>

```

Answer: 
I think this following code is not correct...
 if($username && $password)

Try this 

```
if(!empty($username) && !empty($password))

```
i think it shout be

```
 <?php
if($_POST)
{
$username = $_POST['username'];
$password = $_POST['password'];

if($username && $password) {
    //info is provided
    $queryget = mysql_query("SELECT * FROM users WHERE id='$username' AND password='$password'");
        $numrows = mysql_num_rows($queryget);

        if($numrows != 0) {

            //something has been found
            $_SESSION['id'] = $username;

        } else {
            echo "Wrong username/password";
            echo "<script>alert('Username/Password are wrong');</script>";
            echo "<script language='javascript'>window.location = 'ask_login.php';</script>";
        }
}
else {
    echo "Wrong username/password";
    echo "<script>alert('Username/Password are wrong');</script>";
    echo "<script language='javascript'>window.location = 'ask_login.php';</script>";
}
}
?>

          <form method="POST" action="">
          <input type="submit" name="details" value="Details">
          </form>

            <form method="POST" action="">
        <input type="submit" name="optionB" value="option B">
            </form>

        <form method="POST" action="">
        <input type="submit" name="optionC" value="option C">
            </form>

```