Jump to content


Photo

lost in space


  • Please log in to reply
5 replies to this topic

#1 koritsaki

koritsaki
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 20 April 2006 - 09:45 PM

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>

#2 KrisNz

KrisNz
  • Members
  • PipPipPip
  • Advanced Member
  • 271 posts
  • LocationAuckland, New Zealand

Posted 21 April 2006 - 12:04 AM

[!--quoteo(post=367011:date=Apr 21 2006, 07:45 AM:name=koritsi)--][div class=\'quotetop\']QUOTE(koritsi @ Apr 21 2006, 07:45 AM) View Post[/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.
$row = mysql_fetch_assoc($result);


#3 koritsaki

koritsaki
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 21 April 2006 - 10:31 AM

Anybody there?

#4 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 21 April 2006 - 10:56 AM

<?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) {

}
?>
This should work.
Fixed the "if" issue and used mysql_result to get the values of the user and pass.

Orio.
Think you're smarty?

(Gone until 20 to November)

#5 koritsaki

koritsaki
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 21 April 2006 - 01:23 PM

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>

#6 SharkBait

SharkBait
  • Members
  • PipPipPip
  • Advanced Member
  • 845 posts
  • LocationMetro Vancouver, BC

Posted 21 April 2006 - 03:59 PM

Dont forget to close your <form> tag with </form> when your done with it ;)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users