Click to See Complete Forum and Search --> : arrgghhhh.....vaidate forms


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.

MrCoder
12-20-2007, 09:20 AM
Dont forget to die() or exit after calling header();

graphical_force
12-20-2007, 09:29 AM
Dont forget to die() or exit after calling header();

How would I code that?

The email part is not working. It should at least let me know that the field is empty but it is not.

??

graphical_force
12-20-2007, 10:59 AM
Well, I got the email validator working but I am still having trouble with checking to see if a form is empty. I thought I could just use isset or empty but I may be doing it wrong.

Can someone please show me a example of a simple form validator checking for user input? This is going to be used for the user name and password

Thanks in advance!