phpperson Posted October 17, 2013 Share Posted October 17, 2013 I don't know what i'm doing wrong : <?php if(isset($_POST['username'])&&isset($_POST['password'])) { $username = $_POST['username']; $password = $_POST['password']; $password_hash = md5($password); if (!empty($username)&&!empty($password)) { $query = "SELECT `id` FROM `users` WHERE `username`='$username' AND `password`='$password_hash'"; if ($query_run = mysql_query($query)) { $query_num_rows = mysql_num_rows($query_run); if ($query_num_rows==0) { echo 'Invalid username or password'; } }if ($query_num_rows==1) { $user_id = mysql_result($query_run,0,'id'); $_SESSION['user_id']=$user_id; header('location: require.php'); } }else { header("Location:jquery.php") ; } } ?> <!doctype html> <html> <head> <link type="text/css" rel="stylesheet" href="css.css"/> </head> <body> <div class="lol"> <h1 class="header">Thecatch</h1> <div id="header"></div> </div> <form action="<?php $current_file;?>" method="POST"> <div class="lol3">Email or Username<br/><input class="class1" type="text" name="username" size="19"> <label class="label" for="pass">Password</label> <input class="class2" type="password" name="password" size="19" > <input class="classname" type="submit" Value="LogIn"><br> <input class="check" type="checkbox" name="stay" value="Stay signed In"><p class="para7">Keep me logged in</p><br> </form></div> </body> </html> Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted October 17, 2013 Share Posted October 17, 2013 Your code should be <?php if(isset($_POST['username']) && isset($_POST['password'])) { $username = mysql_real_escape_string($_POST['username']); $password = md5($_POST['password']); if (!empty($username) && !empty($password)) { $query = "SELECT `id` FROM `users` WHERE `username`='$username' AND `password`='$password'"; if ($query_run = mysql_query($query)) { if (mysql_num_rows($query_run) == 1) { $user_id = mysql_result($query_run,0,'id'); $_SESSION['user_id'] = $user_id; header('location: require.php'); } else { echo 'Invalid username or password'; } } else { echo 'Query error: ' . mysql_error(); exit; } } else { header("Location:jquery.php") ; } } ?> <!doctype html> <html> <head> <link type="text/css" rel="stylesheet" href="css.css"/> </head> <body> <div class="lol"> <h1 class="header">Thecatch</h1> <div id="header"></div> </div> <form action="<?php $current_file;?>" method="POST"> <div class="lol3">Email or Username<br/><input class="class1" type="text" name="username" size="19"> <label class="label" for="pass">Password</label> <input class="class2" type="password" name="password" size="19" > <input class="classname" type="submit" Value="LogIn"><br> <input class="check" type="checkbox" name="stay" value="Stay signed In"><p class="para7">Keep me logged in</p><br> </form></div> </body> </html> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.