koritsaki Posted April 20, 2006 Share Posted April 20, 2006 Hello guys and girls! I need some help because I'm new and not so good on programming. The thing is that I have a php login page with a form in it. The form's action is on another page in case username and password are correct. This works fine but I must also have a fail page in case username and password are incorrect or an alert message on submit that will not allow user to leave the home page before entering the correct username and password. This is how the php code looks like:<?php $ena= $_POST[textfield]; //username from home page$dyo = $_POST[textfield2]; //password >> >>$conn = mysql_connect("localhost", "root", "12365875") or die(mysql_error());mysql_select_db("e-kiosk",$conn) or die(mysql_error());$sql = "SELECT username,password FROM customers"; $result = mysql_query($sql,$conn) or die(mysql_error());$user = $row['username']; //username from database$pass = $row['password']; //password >> >> if ($ena!==$user and $dyo!==$pass) {}?>Is there something I can do on submit of the form? I have tried to compine php and javascript there but it doesn't work. What else can i do?This is a small piece of my form:<form name="form1" method="post" action="/loganswer.php"> <p><font color="ff9900"><strong>Username:</strong></font></p> Quote Link to comment Share on other sites More sharing options...
KrisNz Posted April 21, 2006 Share Posted April 21, 2006 [!--quoteo(post=367011:date=Apr 21 2006, 07:45 AM:name=koritsi)--][div class=\'quotetop\']QUOTE(koritsi @ Apr 21 2006, 07:45 AM) [snapback]367011[/snapback][/div][div class=\'quotemain\'][!--quotec--]Hello guys and girls! I need some help because I'm new and not so good on programming. The thing is that I have a php login page with a form in it. The form's action is on another page in case username and password are correct. This works fine but I must also have a fail page in case username and password are incorrect or an alert message on submit that will not allow user to leave the home page before entering the correct username and password. This is how the php code looks like:<?php $ena= $_POST[textfield]; //username from home page$dyo = $_POST[textfield2]; //password >> >>$conn = mysql_connect("localhost", "root", "12365875") or die(mysql_error());mysql_select_db("e-kiosk",$conn) or die(mysql_error());$sql = "SELECT username,password FROM customers"; $result = mysql_query($sql,$conn) or die(mysql_error());$user = $row['username']; //username from database$pass = $row['password']; //password >> >> if ($ena!==$user and $dyo!==$pass) {}?>Is there something I can do on submit of the form? I have tried to compine php and javascript there but it doesn't work. What else can i do?This is a small piece of my form:<form name="form1" method="post" action="/loganswer.php"> <p><font color="ff9900"><strong>Username:</strong></font></p>[/quote]You need a line of code to get the database information you are after. Put this line after you execute your query.[code] $row = mysql_fetch_assoc($result); [/code] Quote Link to comment Share on other sites More sharing options...
koritsaki Posted April 21, 2006 Author Share Posted April 21, 2006 Anybody there? Quote Link to comment Share on other sites More sharing options...
Orio Posted April 21, 2006 Share Posted April 21, 2006 [code]<?php $ena= $_POST[textfield]; //username from home page$dyo = $_POST[textfield2]; //password >> >>$conn = mysql_connect("localhost", "root", "12365875") or die(mysql_error());mysql_select_db("e-kiosk",$conn) or die(mysql_error());$sql = "SELECT username,password FROM customers"; $result = mysql_query($sql,$conn) or die(mysql_error());$user=mysql_result($result, "username", "0");$pass=mysql_result($result, "password", "0");$user = $row['username']; //username from database$pass = $row['password']; //password >> >>if ($ena!=$user && $dyo!=$pass) {}?>[/code]This should work.Fixed the "if" issue and used mysql_result to get the values of the user and pass.Orio. Quote Link to comment Share on other sites More sharing options...
koritsaki Posted April 21, 2006 Author Share Posted April 21, 2006 Thank you so much Orio for your reply. The thing is that the query work fine. What i need to do is to fix the if statement so if (isset($_Post ['Submit'])) { // i suppose this is what i have to write in order when the submit button of my form is pressed. My question is how to load the same page there before the form's action redirects me to another page. You see I have a form later in the page that looks like this:<form name="form1" method="post" action="/loganswer.php"><p><font color="ff9900"><strong>Username:</strong></font></p> Quote Link to comment Share on other sites More sharing options...
SharkBait Posted April 21, 2006 Share Posted April 21, 2006 Dont forget to close your <form> tag with </form> when your done with it ;) 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.