Jump to content

Archived

This topic is now archived and is closed to further replies.

koritsaki

lost in space

Recommended Posts

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>

Share this post


Link to post
Share on other sites
[!--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]

Share this post


Link to post
Share on other sites
[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.

Share this post


Link to post
Share on other sites
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>

Share this post


Link to post
Share on other sites
Dont forget to close your <form> tag with </form> when your done with it ;)

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.