Script Center >
Scripting Forums
>
The Official Scripting Guys Forum!
>
Help Debugging PHP Register Form
Help Debugging PHP Register Form
- <?php
$username = $_POST["username"];
$password = $_POST["password"];
$email = $_POST["email"];
$conf_pass = $_POST["confirm"];
$error = false;
$connect = mysql_connect("localhost", "stickmi1_data", "electricCompany");
$database = mysql_select_db("account", $connect);
$usernameCheck = mysql_query("SELECT username FROM users WHERE username = '$username'");
// Registration Form Validation Script
if(!$username || !$password || !$email || !$conf_pass)
{
$error = true;
$errorMessage = "Please fill in any missing fields before continuing!";
}
else if($password != $conf_pass);
{
$error = true;
$errorMessage = "Your password and confirmation password don't match!";
}
else if($usernameCheck > 0)
{
$error = true;
$errorMessage = "The requested username is already in use, try another!";
}
else if($error == false)
{
$password = md5($password);
mysql_query("INSERT INTO users(username, password, email) VALUES($username, $password, $email)");
}
?>
<form method="post" name="registerForm">
Username: <input type="text" name="username" />
Password: <input type="password" name="password" /><br />
Confirm Password: <input type="password" name="conf_pass" />
Email: <input type="text" name="email" />
</form>
All Replies
- What is the problem?
Do you get an error?
Karl - No, it won't put the Data in the Database.
- <?php
if(isset($_POST['register']))
{
$username = $_POST["username"];
$password = $_POST["password"];
$email = $_POST["email"];
$conf_pass = $_POST["confirm"];
$error = false;
$connect = mysql_connect("localhost", "stickmi1_data", "electricCompany");
$database = mysql_select_db("account", $connect);
$usernameCheck = mysql_query("SELECT username FROM users WHERE username = '$username'");
// Registration Form Validation Script
if(!$username || !$password || !$email || !$conf_pass)
{
$error = true;
$errorMessage = "Please fill in any missing fields before continuing!";
}
else if($password != $conf_pass);
{
$error = true;
$errorMessage = "Your password and confirmation password don't match!";
}
if($usernameCheck > 0)
{
$error = true;
$errorMessage = "The requested username is already in use, try another!";
}
if($error == false)
{
$password = md5($password);
mysql_query("INSERT INTO users(username, password, email) VALUES($username, $password, $email)",$connect);
}
}
?>
<form name="register_form" method="post">
<table>
<tr>
<td>Username: </td>
<td><input type="text" name="username" /></td>
</tr>
<tr>
<td>Password: </td>
<td><input type="password" name="password" /></td>
</tr>
<tr>
<td>Confirm Pass: </td>
<td><input type="password" name="conf_pass" /></td>
</tr>
<tr>
<td>Email: </td>
<td><input type="text" name="email" /></td>
</tr>
<tr>
<td><input type="submit" name="register" value="Register" /></td>
</tr>
</table>
</form>
Here is the updated script. - Seems more like a web development/PHP/SQL question than a Windows administrative scripting question.
Bill

