Jump to content

lost in space


koritsaki

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>
Link to comment
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]
Link to comment
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.
Link to comment
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>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.