Jump to content

Trying To Use Regular Expressions To Validate A Form But My Web Page Isn't Loading.


chdze

Recommended Posts

I trying to use regular expressions to validate my register from, but when i try to check it the internet, i get errors. I skimmed through the code several times but I can't find the error. He's the code:

 

<?php

$name=$_POST['name'];

$address=$_POST['address'];

$city=$_POST['city'];

$phone=$_POST['phone'];

$email=$_POST['email'];

$username=$_POST['username'];

$password=$_POST['password'];

 

if(mysql_connect('***','***','***'))

print "<h2>Thank you for Signing Up!</h2>";

mysql_select_db('Info1');

$query="INSERT INTO UserInfo (Name, Address , City, Phone, Email, Username, Password) VALUES ('$name', '$address', '$city', '$phone', '$email', '$username', '$password')";

 

$pattern_name="^([a-z A-Z] [[:blank]] [a-z A-Z])$";

$string_name=$_POST['name'];

 

$valid_name=ereg($pattern_name, $string_name);

 

$pattern_phone="^([0-9]{3})-([0-9]{4})$";

$string_phone=$_POST['phone'];

 

$valid_phone=ereg($pattern_phone,$string_phone);

 

$pattern_address="^([0-9] [[:blank]] [a-z A-Z])$";

$string_address=$_POST['address'];

 

$valid_address=($pattern_address, $pattern_string);

 

if (!$valid_phone) {

print "Error, Phone number must follow 111-1111 format.";

}

else if (!$valid_name) {

print "Error, Please Enter First and Last name (letters only!)";

}

else if (!$valid_address) {

print "Error, Please Enter your Address (Building number and Street)";

}

else if ($valid_name, valid_phone, valid_address) {

mysql_query($query);

}

 

 

mysql_close();

?>

 

here's the url: http://storm.cis.fordham.edu/~lasbrey/re…

(its nothing fancy, just started learning)

 

thanks.

Link to comment
Share on other sites

what do you mean you "get errors"?

ereg() is depreciated, whatever resource your learning from is out of date, you should be using preg_....() instead.

You shouldn't really use a regex on names, unless you plan on checking against all accented characters and the suck, but still, if you want to force someone to use first and last name, use two mandatory fields.

PHP has a better way of validating and sanitizing most form input using filter_vars() and either a validate filter or a sanitise filter.

 

I would suggest you have a long rethink about what using regex validation will do to your form in real terms.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.