javascript - Dropdown sign in menu -
i'm using jquery animate dropdown sign in div. sign form uses php check if user exists in database. however, if echo dropdown menu goes away , have click again see error message. here's how login looks:
<form method="post"> <input type="text" name="username" placeholder="username" required> <input type="password" name="password" placeholder="password" required> <input type="submit" name="button" value="sign in"> </form> <?php session_start(); $username = $_post["username"]; $password = $_post["password"]; include("connect.php"); if($username && $password){ $password = md5($password); $getquery = mysql_query("select * users username='$username' , password = '$password'"); $numrows = mysql_num_rows($getquery); if($numrows != 0){ setcookie('username', $username, time()+3600); } else { echo "invalid username."; } } ?>
jsfiddle: http://jsfiddle.net/3rr9w/1/
as see, when press submit button dropdown menu goes again.
as stated in comment, suggest using ajax call (just search google jquery ajax call php).
for answering current problem without making things more complicated, add end of code:
<script> <?php if ($_post['username']) { echo 'var postback = true;'; } else { echo 'var postback = false;' } ?> if (postback) { $("#signin").show(); } </script>
- you can make signin visible default , hide if postback false.
Comments
Post a Comment