xxreenaxx1 Posted March 9, 2010 Share Posted March 9, 2010 I was woking on these two codes belwo, when I try to enter the username and the password. It just shows me the same page again. <?php $username =$_POST['username']; $password =$_POST['password']; $login1 =$_GET['login1']; setcookie("username","$username",time()+86400); if($login=='yes'){ $con = mysql_connect("localhost","root",""); mysql_select_db("login"); $get = mysql_query("SELECT count(id) FROM login WHERE user='$username' and pass='$password'"); $result = mysql_result($get, 0); if($resut!=1){ echo "Invalid login"; } else { echo "Login Successful, Welcome back".$_COOKIE['username']."sir/madam"; $_SESSION['username']=$username; } } <html> <body> <form action"login1.php?login=yes" method="POST"> Username:<input type="text" name="username" /> <br/> <br/> Password:<input type="password" name ="password"/> <br /> <input type="submit" value="Submit" /> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/194676-log-in-with-mysql/ Share on other sites More sharing options...
aeroswat Posted March 9, 2010 Share Posted March 9, 2010 On your second page of code you are missing an equals sign in the form action and I don't believe you can include the ?login=yes in that form action. It must specifically be a file you are sending to. the ?login=yes would be a GET variable which is another form method Quote Link to comment https://forums.phpfreaks.com/topic/194676-log-in-with-mysql/#findComment-1023800 Share on other sites More sharing options...
xxreenaxx1 Posted March 9, 2010 Author Share Posted March 9, 2010 Oh, well I have removed ?login=yes. and it doesnt output anything. Also I have noticed I forgot to close my php. But even when I do this, its not working. Quote Link to comment https://forums.phpfreaks.com/topic/194676-log-in-with-mysql/#findComment-1023813 Share on other sites More sharing options...
aeroswat Posted March 9, 2010 Share Posted March 9, 2010 Oh, well I have removed ?login=yes. and it doesnt output anything. Also I have noticed I forgot to close my php. But even when I do this, its not working. did you add the equal sign after <form action like I told you? Quote Link to comment https://forums.phpfreaks.com/topic/194676-log-in-with-mysql/#findComment-1023816 Share on other sites More sharing options...
xxreenaxx1 Posted March 9, 2010 Author Share Posted March 9, 2010 Yes, I did <html> <body> <form action="login.php" method="POST"> Username:<input type="text" name="username" /> <br/> <br/> Password:<input type="password" name ="password"/> <br /> <input type="submit" value="Submit" /> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/194676-log-in-with-mysql/#findComment-1023829 Share on other sites More sharing options...
aeroswat Posted March 9, 2010 Share Posted March 9, 2010 Yes, I did <html> <body> <form action="login.php" method="POST"> Username:<input type="text" name="username" /> <br/> <br/> Password:<input type="password" name ="password"/> <br /> <input type="submit" value="Submit" /> </form> </body> </html> Why are you checking if login == 1 on login.php? There's no need for that. Take that out. Quote Link to comment https://forums.phpfreaks.com/topic/194676-log-in-with-mysql/#findComment-1023832 Share on other sites More sharing options...
xxreenaxx1 Posted March 9, 2010 Author Share Posted March 9, 2010 Do you mean login ==yes.. well, I have taken that out.. It keeps telling me Invalid login <html> <body> <form action="login.php" method="POST"> Username:<input type="text" name="username" /> <br/> <br/> Password:<input type="password" name ="password"/> <br /> <input type="submit" value="Submit" /> </form> </body> </html> <?php $username =$_POST['username']; $password =$_POST['password']; $login =$_GET['login']; setcookie("username","$username",time()+86400); $con = mysql_connect("localhost","root",""); mysql_select_db("login"); $get = mysql_query("SELECT count(id) FROM login WHERE user='$username' and pass='$password'"); $result = mysql_result($get, 0); if($resut!=1){ echo "Invalid login"; } else { echo "Login Successful, Welcome back".$_COOKIE['username']."sir/madam"; $_SESSION['username']=$username; } ?> these are my updated codes Quote Link to comment https://forums.phpfreaks.com/topic/194676-log-in-with-mysql/#findComment-1023844 Share on other sites More sharing options...
aeroswat Posted March 9, 2010 Share Posted March 9, 2010 You need to slow down when you are writing your code. You keep making spelling errors and other such things. In your if statement $result is spelled wrong. You left out the lowercase "L". Also there is no need to do if($result!=1) You should be able to just do if(!$result) Quote Link to comment https://forums.phpfreaks.com/topic/194676-log-in-with-mysql/#findComment-1023851 Share on other sites More sharing options...
xxreenaxx1 Posted March 9, 2010 Author Share Posted March 9, 2010 OMGGG.... it worked, i have tired like 100rd of way to do this.. but thank you soooooooo much.. I will slow down next time.. but thank youuuu Quote Link to comment https://forums.phpfreaks.com/topic/194676-log-in-with-mysql/#findComment-1023861 Share on other sites More sharing options...
aeroswat Posted March 9, 2010 Share Posted March 9, 2010 OMGGG.... it worked, i have tired like 100rd of way to do this.. but thank you soooooooo much.. I will slow down next time.. but thank youuuu Not a problem at all man. Good luck with your site. Quote Link to comment https://forums.phpfreaks.com/topic/194676-log-in-with-mysql/#findComment-1023863 Share on other sites More sharing options...
xxreenaxx1 Posted March 9, 2010 Author Share Posted March 9, 2010 one correction, I am a women... Quote Link to comment https://forums.phpfreaks.com/topic/194676-log-in-with-mysql/#findComment-1023864 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.