Login Validation Problem [solved]
Posted: Thu Mar 26, 2009 8:21 pm
Hey guys, I am rather new at php programming and have run into a problem when trying to validate a login script. The php script is ignored when the form is submitted and the form just executes its action and directs the browser to the next page. If anyone has any insight as to my errors, please let me know, it is greatly appreciated.
HTML script
PHP script
HTML script
Code: Select all
<html>
<div id="content2"><form action="preferences.php" method="post">
<table width="250" border="0" cellpadding="3" id="border">
<tr>
<td><img src="images/createwriting.gif"></td>
</tr>
<tr>
<td class="redtext">Create Username: <input name="username" type="text" size="40" maxlength="50"/></td>
</tr>
<tr>
<td class="redtext">Create Password: <input name="password" type="password" size="40" maxlength="50"/></td>
</tr>
<tr>
<td class="redtext">Confirm Password: <input name="confirm_password" type="password" size="40" maxlength="50"/></td>
</tr>
<tr>
<td align="right"><input name="submit" type="image" src="images/createbutton.gif" />
</html>Code: Select all
<?php
if (isset($_POST['submit'])){
$username=mysql_real_escape_string($_POST["username"]);
$password=$_POST["password"];
$confirm_password=$_POST["confirm_password"];
$first_query="SELECT * FROM users WHERE username ='$username'";
$result=mysql_query($first_query);
$count=mysql_num_rows($result);
if ($password==""){
echo 'please fill in all fields';
die();
}
else if ($username==""){
echo 'please fill in all fields';
die();
}
else if ($confirm_password==""){
echo 'please fill in all fields';
die();
}
else if ($count>0){
echo 'user exists';
die();
}
else if ($password!=$confirm_password){
echo 'passwords do not match';
die();
}
else{
$second_query = "INSERT INTO users (username,password) VALUES ('$username', '$password')";
mysql_query($second_query) or die('Error, insert query failed');
}
}
?>