View Single Post
  #13 (permalink)  
Old 11-01-09, 10:01 PM
PopSmith PopSmith is offline
Newbie Coder
 
Join Date: May 2009
Posts: 18
Thanks: 5
Thanked 0 Times in 0 Posts
Sorry for the bump, it seems the forum has a time limit before you can't edit a post anymore which is why I am posting this instead of editing my previous post:

I was debugging my form earlier and decided to add echoes due to it's strange behavior to see if I could tell where it's getting stuck. I added echoes after specific events so I could tell where the code stops processing.


The code appears to be getting stuck on the preg_matches, here is the php part of the code. Other than the echoes I haven't changed any code from my previous post. If I fix the problem I'll report back:

php Code:
  1. <?php
  2. if (isset($_POST&#91;'submitted'])) {
  3.         echo "Successful submit!";
  4.         require_once('../includes/sanitize.php');
  5.    
  6.         //Sanitize data before validation
  7.         $c_fname = sanitize(3, 15, $_POST&#91;'first_name']);
  8.         $c_lname = sanitize(3, 25, $_POST&#91;'last_name']);
  9.         $c_email = sanitize(5, 60, $_POST&#91;'email']);
  10.         $c_email_2 = sanitize(5, 60, $_POST&#91;'email_2']);
  11.        
  12.         echo "Sanitization complete!";
  13.        
  14.         require_once(MYSQL);
  15.        
  16.         echo "MySQL included!";
  17.        
  18.         //Validate the first name
  19.         return preg_match("/^[a-zA-Z\.]{1,15}/", $c_fname);
  20.        
  21.         echo "Preg_match for first name should have worked!";
  22.        
  23.         //Validate last name
  24.         return preg_match("/^
  25.         [a-zA-Z\-.]{1,25}/", $c_lname);
  26.        
  27.         echo "Name(s) validated!";
  28.        
  29.         //Is the email valid and not empty?
  30.         if (empty($c_email_2)) {
  31.             echo '<p>Please enter your email address in both fields.</p>';
  32.         } else if ($c_email != $c_email_2) {
  33.             echo '<p>The email fields do not match. Please confirm them again.</p>';
  34.         } else {
  35.             function isValidEmail( $c_email = null ) {
  36.             return preg_match( "/^
  37.             [\d\w\/+!=#|$?%{^&}*`'~-]
  38.             [\d\w\/\.+!=#|$?%{^&}*`'~-]*@
  39.             [A-Z0-9]
  40.             [A-Z0-9.-]{1,60}
  41.             [A-Z0-9]\.
  42.             [A-Z]{2,6}/", $c_email);
  43.                 }
  44.         }
  45.        
  46.         echo "Emails are valid!";
  47.  
  48.         if (!empty($c_email) && $c_email == $c_email_2) {
  49.             $access = "SELECT Email FROM customers WHERE Email='$c_email'";
  50.             $r = mysqli_query($dbc, $access) or trigger_error("Query: $access\n<br />MySQL error: " . mysqli_error($dbc));
  51.         }
  52.        
  53.         //Insert information if email is unique:
  54.         if (mysqli_num_rows($r) == 0) {
  55.             $access = "INSERT INTO customers (Email, First, Last) VALUES ('$c_email', '$c_fname', '$c_lname')";
  56.             $r = mysqli_query($dbc, $access) or trigger_error("Query: $access\n<br />MySQL error: " . mysqli_error($dbc));
  57.         } else {
  58.             echo '<p>Your email address could not be recorded due to an error, please try again.</p>';
  59. }
  60. mysqli_close($dbc);
  61. } // End Submit IF.
  62. ?>