Username Password
Posted: Thu Apr 01, 2004 8:26 am
Wondering can anyone tell me what i could do with the code below...i have a login page programmed in HTML;where the user enters their username and password, then i have an adminlogin page which checks the iput..the problem is that by the time the user presses the sumbit button it goes right to the adminlogin page regardless of what they entered...could i put all the code in one form; if what they summit is correct,goes to another page: if incorrect stays on that form...hope this makes sense!!!
Code!
LOGIN.PHP
<html>
<head><title>Admin Login</title></head>
<body>
<body text="blue" BGCOLOR="FFFFCC">
<center><img src="http://www.webcom.com/graphics/formt.gif"
width=150 height=100</center>
<center>
<font size="3"><p align=center>
<h1>Admin Login</h1>
</center>
<p>
<form action="adminlogin.php" method="post">
Enter user name: <input type="text" name="username"><p>
Enter password: <input type="password" name="password"><p>
<input type='submit' value='submit'>
</form>
</body>
</html>
ADMINLOGIN
<html>
<head><title>Admin Login</title></head>
<body>
<h1><center>Admin Login</center></h1>
<body text="blue" BGCOLOR="FFFFCC">
<center>
</center>
<p>
<center><img src="http://www.webcom.com/graphics/formt.gif"
width=150 height=100</center>
<br>
<align="center"><font size="3"><a href="http://~u2ell/flightsinput.php"><FONT COLOR="red">Enter Flight Details</a></font>
<br>
<align="center"><font size="3"><a href="http://~u2ell/flightpricesinput.php"><FONT COLOR="red">Enter Flight Prices</a></font>
</body>
</html>
Thanks.
Code!
LOGIN.PHP
<html>
<head><title>Admin Login</title></head>
<body>
<body text="blue" BGCOLOR="FFFFCC">
<center><img src="http://www.webcom.com/graphics/formt.gif"
width=150 height=100</center>
<center>
<font size="3"><p align=center>
<h1>Admin Login</h1>
</center>
<p>
<form action="adminlogin.php" method="post">
Enter user name: <input type="text" name="username"><p>
Enter password: <input type="password" name="password"><p>
<input type='submit' value='submit'>
</form>
</body>
</html>
ADMINLOGIN
<html>
<head><title>Admin Login</title></head>
<body>
<h1><center>Admin Login</center></h1>
<body text="blue" BGCOLOR="FFFFCC">
<center>
Code: Select all
<?php
$user="";
$host="";
$password="";
$database="";
$connection = mysql_connect($host,$user,$password)
or die ("connection to server failed.");
$connection = mysql_connect($host,$user,$password)
or die ("couldn't connect to server");
$db = mysql_select_db($database,$connection)
or die ("Couldn't select database");
$password= $HTTP_POST_VARS['password'];
$username=$HTTP_POST_VARS['username'];
$query ="SELECT password FROM users WHERE username= '$username'";
$result = mysql_query($query)
or die("couldn't excute query.");
$row = mysql_fetch_array($result,MYSQL_ASSOC);
if ($username == $row['password'])
{
/* this only outputs the password as it is the only thing called in the query*/
echo "<h1>$username:</h1>";
echo "<h1>valid password!</h1>";
$query1 = "SELECT * FROM users WHERE username= '$username'";
$result1 = mysql_query($query1)
or die("couldn't excute query.");
while ($row1 = mysql_fetch_array($result1))
{
extract($row1);
echo " <table border = 2 width=70%>";
}
echo "</table>";
}
else
{
echo "<h1>invalid User name or password</h1>";
echo "<h2>Please retype!!<h2>";
}
?></center>
<p>
<center><img src="http://www.webcom.com/graphics/formt.gif"
width=150 height=100</center>
<br>
<align="center"><font size="3"><a href="http://~u2ell/flightsinput.php"><FONT COLOR="red">Enter Flight Details</a></font>
<br>
<align="center"><font size="3"><a href="http://~u2ell/flightpricesinput.php"><FONT COLOR="red">Enter Flight Prices</a></font>
</body>
</html>
Thanks.