I want to make a PHP page that reads from a mySQL Database.. This page displays two fields for the user : 1- Username. 2- Password.
Now in the database there are many columns.. each one has many fields :
Username, Password, Serial, Phone No., Address..Etc..
Now I want the PHP file to take the Username and Password after the user enter them in the fields and compare them with the ones inside the database.. if they are the same.. the serial field inside the database will send its value to the PHP page.. which will echo it as a variable ($var) there..
Ok, here goes a crazy experiment:
Agreement:
To read and use the code below, you must first send $50 via paypal to the email address this message came from.
The following code is untested and may have errors, if the $50 shows up via pay pal I will help fix any errors this code may have.
Login.html:
<HTML> <HEAD> <SCRIPT> function selectit() { document.forms["Login"].elements["UserName"].focus(); } </SCRIPT> </HEAD> <BODY> <form NAME="Login" ACTION="/Login.php" METHOD="POST"> <B>Log In:</B><BR> User Name: <input TYPE="TEXT" SIZE="17" MAXLENGTH="16" NAME="UserName"><br> Password: <input TYPE="PASSWORD" SIZE="17"MAXLENGTH="16" NAME="Password"><br> <input TYPE="SUBMIT" NAME="SUBMIT" VALUE="Log In"><br> </FORM> </BODY></HTML>
Login.php <?php
$link = mysql_connect($MySQLHost, $MySQLUser, $MySQLPass) or die("Could not connect: " . mysql_error());
mysql_select_db("dbname", $link);
$UserName = stripslashes($_POST['UserName']); $Password = stripslashes($_POST['Password']);
$User = mysql_real_escape_string(trim($UserName)); $query = "SELECT Serial, Password from user where UserName='$User'"; $result = mysql_query($query) or die("Query errort: " . mysql_error()); $row = mysql_fetch_row($result) or die("User Not found: " . mysql_error()); $Serial = htmlspecialchars($row[0]); $UserPassword = $row[1]; mysql_close($link);
if($UserPassword == $Password){ print<<<END <HTML> <BODY> Serial: $Serial </BODY></HTML> END;
}else{ print<<<END <HTML> <BODY> Sorry, wrong password! </BODY></HTML> END; } ?>
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php