Login Problem with Mysql from PHP Hey Guys i have problem in coding of creating a login page with mysql database connectivity from php so anyone here kindly help me out
<? session_start(); //your db connection if(isset($_POST[username]) && isset($_POST[password])){ $q = mysql_query("SELECT * FROM users WHERE username = '".mysql_real_escape_string($_POST[username])."' AND password ='".md5($_POST[password])."' LIMIT 1"); $n = mysql_num_rows($q); if($n == 0){ echo "Wrong username and/or password"; }else{ $_SESSION[username] = $_POST[username]; $_SESSION[password] = md5($_POST[password]); echo '<script>window.location=window.location</script>'; //Just to refresh the current page. } if(!$_SESSION[username] || !$_SESSION[password]){ ?> <form action="" method="post"> Username: <input type="text" name="username" /><br /> Password: <input type="password" name="password" /><br /> <input type="submit" value="Log in" /> </form> <? }else{ echo "Welcome, ".$_SESSION[username].".<br /> You are now logged in."; } ?> PHP: Just made quickly in the school, not tested at all, but it should work perfect