rainprop Posted March 19, 2010 Share Posted March 19, 2010 Hi... Im creating a simple login page, and i got a parse error..may i know how to fix it?? $username = $_POST['username']; # make a md5 password. $md5_password = md5($_POST['password']); $query = mysql_query("select * from user where username = "$username" and password = "$md5_password""); thank u to whoever replies... Quote Link to comment https://forums.phpfreaks.com/topic/195788-parse-error/ Share on other sites More sharing options...
slurpee Posted March 19, 2010 Share Posted March 19, 2010 $username = $_POST['username']; # make a md5 password. $md5_password = md5($_POST['password']); $query = mysql_query("select * from user where username = '$username' and password = '$md5_password'"); Quote Link to comment https://forums.phpfreaks.com/topic/195788-parse-error/#findComment-1028513 Share on other sites More sharing options...
rainprop Posted March 19, 2010 Author Share Posted March 19, 2010 it only created more errors.. Notice: Undefined index: username in C:\wamp\www\login2.php on line 17 Notice: Undefined index: password in C:\wamp\www\login2.php on line 19 Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\login2.php on line 23 Wrong Username or Password Quote Link to comment https://forums.phpfreaks.com/topic/195788-parse-error/#findComment-1028515 Share on other sites More sharing options...
Deoctor Posted March 19, 2010 Share Posted March 19, 2010 paste ur entire code.. and also have u made the connection to the databse Quote Link to comment https://forums.phpfreaks.com/topic/195788-parse-error/#findComment-1028516 Share on other sites More sharing options...
rainprop Posted March 19, 2010 Author Share Posted March 19, 2010 yup, i have already made the connection... login2.php <?php session_start(); require_once 'database.php'; $username = $_POST['username']; $md5_password = md5($_POST['password']); $query = mysql_query("select * from user where username = '$username' and password = '$md5_password'"); if(mysql_num_rows($query) > 0) { $result = mysql_fetch_assoc($query); $_SESSION['username'] = $_POST['username']; header("location:index.php"); } else{ echo "Wrong Username or Password"; } ?> <form name="back" method="post" action="login.php"> <input type="submit" name="back" id="back" value="Back to Home"> index.php <?php session_start(); require_once 'database.php'; if (isset($_SESSION['username'])){ echo "Welcome ".$_SESSION['username']; ?> <form name="logout" method="post" action="logout.php"> <input type="submit" name="logout" id="logout" value="Logout"> </form> <br /><form name="news" method="post" action="news.php"> <input type="submit" name="news" id="news" value="News"> </form> <?php } elseif(isset($_SESSION['admin'])){ echo"Welcome ".$_SESSION['admin']; echo"<br><br>You are logged in as an Admin"; ?> <form name="logout" method="post" action="logout.php"> <input type="submit" name="logout" id="logout" value="Logout"> </form> <?php }else{ ?> <form name="login_form" method="post" action="login2.php"> <label> <input name="user" type="text" id="user">ID<br /> <input name="pass" type="password" id="pass">Password<br /> </label> <input type="submit" name="login" id="login" value="Login"> </label> </p> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/195788-parse-error/#findComment-1028520 Share on other sites More sharing options...
rainprop Posted March 19, 2010 Author Share Posted March 19, 2010 this is code.pls help..the previous one is wrong.. login2.php <?php session_start(); require_once 'database.php'; $username = $_POST['username']; $md5_password = md5($_POST['password']); $query = mysql_query("select * from user where username = '$username' and password = '$md5_password'"); if(mysql_num_rows($query) > 0) { $result = mysql_fetch_assoc($query); $_SESSION['username'] = $_POST['username']; header("location:index.php"); } else{ echo "Wrong Username or Password"; } ?> <form name="back" method="post" action="login.php"> <input type="submit" name="back" id="back" value="Back to Home"> index.php <?php session_start(); require_once 'database.php'; if (isset($_SESSION['username'])){ echo "Welcome ".$_SESSION['username']; ?> <form name="logout" method="post" action="logout.php"> <input type="submit" name="logout" id="logout" value="Logout"> </form> <br /><form name="news" method="post" action="news.php"> <input type="submit" name="news" id="news" value="News"> </form> <?php } elseif(isset($_SESSION['admin'])){ echo"Welcome ".$_SESSION['admin']; echo"<br><br>You are logged in as an Admin"; ?> <form name="logout" method="post" action="logout.php"> <input type="submit" name="logout" id="logout" value="Logout"> </form> <?php } ?> login.php <form name="login_form" method="post" action="login2.php"> <label> <input name="username" type="text" id="username">Username<br /> <input name="password" type="password" id="password">Password<br /> </label> <input type="submit" name="login" id="login" value="Login"> </label> </p> Quote Link to comment https://forums.phpfreaks.com/topic/195788-parse-error/#findComment-1028612 Share on other sites More sharing options...
True`Logic Posted March 19, 2010 Share Posted March 19, 2010 $username = $_POST['username']; $query = mysql_query("select * from user where username =\"$username\""); if($query["password"] == md5($_POST['password'])) { // success } else { // fail } don't forget to check datbase.php and make sure the info contained is correct. Check your mysql database and make sure your table user contaisn the correct fields. If the password in the database is saved as md5, you're good, if not, use md5() on $query[password] as well. Quote Link to comment https://forums.phpfreaks.com/topic/195788-parse-error/#findComment-1028650 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.