I got this php script from a book essential PHP for web professionals.
Unfortunately this does not work, because as soon as it is run, the if statement is run as if that submit is set, when it is not. I don't know but could this be because of global variables are turned off? Like I said it acts as if $submit is set.
neubie
Code is below:
<html>
<head>
<title>Password Checking Script</title>
</head>
<body>
<?php
function print_form() {
?>
<form action="check_password.php3" method="POST">
<h3>Please Login</h3>
User Name: <input type="text" name="user_name">
<br>Password: <input type="password" name="password">
<input type="submit" name="submit" value="Login!">
</form>
<?
}
if(isset($submit)):
if(!$db = mysql_connect("localhost","root")):
print("<h1>Can't Connect to the DB!</h1>\n");
else:
mysql_select_db("php3", $db);
endif;
$sql = "select * from users where user_name = '$user_name'";
$result = mysql_query($sql);
$row_count = mysql_num_rows($result);
if($row_count == 0):
?>
<h3>Wrong User Name! Try Again</h3>
<?
print_form();
else:
$row = mysql_fetch_array($result);
if($password != $row["user_password"]):
?>
<h3>Incorrect Password! Try Again</h3>
<?
print_form();
else:
?>
<h3>Password Accepted!</h3>
<?
endif;
endif;
else:
print_form();
endif;
?>
</body>
</html>