Hi guys,
I am trying to create a few rules when the submit button is pressed:
it should check if the field are empty and show a error message,
if the fields are not empty then strcmp the 2 fields named "email" and "email2"
check if all the field have data in them Using the "field_validator" function
if all these condition are met then run function "new user"
I have listed the code below...
thanks for any help
while(isset($_POST["submit"]))
// Info has been submitted, check it:
if(!empty($messages))
{
displayErrors($messages);
$messages="error";
echo "$messages";// Check login, password and password2 are not empty:
}
else
{
// registration ok, get user id and update db with new info:
newUser($_POST["name"], $_POST["password"], $_POST["age"] );
echo " this worked innt";
}
if(strcmp($_POST["email"], $_POST["email2"]))
{
// The password and confirmation password didn't match,
// Add a message to be displayed to the user:
$messages="Your passwords did not match";
echo $messages;
}
elseif( ($row=mysql_fetch_array($result)) )
{
$messages[]="Name \"".$_POST["name"]."\" already exists. Try another.";
}
#field_validator($field_descr, $field_data, $field_type, $min_length="", $max_length="", $field_required=1)
field_validator("name", $_POST["name"], "alphanumeric", 4, 30);
field_validator("email", $_POST["email"], "string", 4, 30);
field_validator("confirm email", $_POST["email2"], "string", 4, 30);
field_validator("age", $_POST["age"], "string", 1, 3);
$query="SELECT * FROM users WHERE name='".$_POST["name"]."'";
//$query="SELECT login FROM users WHERE login='".$_POST["login"]."'";
$result=mysql_query($query, $link) or die("MySQL query $query failed. Error if any: ".mysql_error());