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: 
`<form action="#">`. no action means 'submit to current url', the pound sign mean 'the current document' and should not navigate. though i'm not sure forms semantically allow this.
I would recommend posting the form data over ajax though. Its not hard to do, Jquery offers the most used ajax function and you basically loop though each input in a form and push the value into a uri-encoded string and post that via an ajax call.
you can use jquery to process the form

```
$.post( "test.php", $( "#testform" ).serialize(),function(e){alert(e);} );

```

test.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>";
}

?>

```

<http://api.jquery.com/jquery.post/>

beware, no input validation!

read this page

<http://www.php.net/manual/en/function.mysql-real-escape-string.php>