chdze Posted December 19, 2012 Share Posted December 19, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/272160-trying-to-use-regular-expressions-to-validate-a-form-but-my-web-page-isnt-loading/ Share on other sites More sharing options...
Muddy_Funster Posted December 19, 2012 Share Posted December 19, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/272160-trying-to-use-regular-expressions-to-validate-a-form-but-my-web-page-isnt-loading/#findComment-1400254 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.