graphical_force
12-20-2007, 09:00 AM
I am trying to check to see if three forms are filled out and I cant seem to get it right.
I have 3 fields that needs to be filled out, I was just starting with the email and here is what I have so far. I know I need to validate the email part, but the user name and password I just want to make sure they get filled out.
here is my code:
<?php
if (!empty($_REQUEST['newemail'])) {
header( "Location: register.php" );
}
$dbNewUser = $_REQUEST['newuser']; // this gets the user name from the register.php form
$dbNewPassword = $_REQUEST['newpassword']; // this gets the password from the register.php form
$dbNewEmail = $_REQUEST['newemail']; // this gets the password from the register.php form
$dbh=mysql_connect ("localhost", "hrpjeff_root", "password") or die ('I cannot connect to the database because: ' . mysql_error()); // this connects to the database or dies
mysql_select_db ("hrpjeff_time"); // this is the name of the database
if(mysql_num_rows(mysql_query("SELECT name FROM users WHERE name = '$dbNewUser'"))){
header( "Location: register.php?bad=1" );
} // this checks to see if the user name is already taken and sends it back to the register page if it is taken
else {
$query = "INSERT INTO users (id, name, password, email) VALUES ( 0, '$dbNewUser', MD5( '$dbNewPassword'), '$dbNewEmail' )"; // this inserts the new user name, password and email into the table
$result = mysql_query($query) or die("Query failed: " . mysql_error()); // if it is not saved then a error is thrown
header( "Location: index.php?" );
}
?>
Any ideas?
Thanks.
I have 3 fields that needs to be filled out, I was just starting with the email and here is what I have so far. I know I need to validate the email part, but the user name and password I just want to make sure they get filled out.
here is my code:
<?php
if (!empty($_REQUEST['newemail'])) {
header( "Location: register.php" );
}
$dbNewUser = $_REQUEST['newuser']; // this gets the user name from the register.php form
$dbNewPassword = $_REQUEST['newpassword']; // this gets the password from the register.php form
$dbNewEmail = $_REQUEST['newemail']; // this gets the password from the register.php form
$dbh=mysql_connect ("localhost", "hrpjeff_root", "password") or die ('I cannot connect to the database because: ' . mysql_error()); // this connects to the database or dies
mysql_select_db ("hrpjeff_time"); // this is the name of the database
if(mysql_num_rows(mysql_query("SELECT name FROM users WHERE name = '$dbNewUser'"))){
header( "Location: register.php?bad=1" );
} // this checks to see if the user name is already taken and sends it back to the register page if it is taken
else {
$query = "INSERT INTO users (id, name, password, email) VALUES ( 0, '$dbNewUser', MD5( '$dbNewPassword'), '$dbNewEmail' )"; // this inserts the new user name, password and email into the table
$result = mysql_query($query) or die("Query failed: " . mysql_error()); // if it is not saved then a error is thrown
header( "Location: index.php?" );
}
?>
Any ideas?
Thanks.