jordanwb Posted March 16, 2009 Share Posted March 16, 2009 I made a website for a friend which included the ability to signup for a newsletter. My friend keeps saying that when he tries to sign up, it says that his email address is invalid (I use regex pattern for that). I try it on my machine and it goes through just fine. He had a friend try his email address and they didn't go through, but again on my machine they did. I use Firefox on Ubuntu, my friend uses IE 7 on Vista, and his friend probably uses some version of IE. Here's the little code block: $first_name = mysql_real_escape_string (trim ($_POST['first_name'])); $last_name = mysql_real_escape_string (trim ($_POST['last_name'])); $email_addr = trim ($_POST['email_addr']); if (preg_match ('#^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.(?:[A-Z]{2}|com|ca|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum)$#i', $email_addr)) { $query = 'INSERT INTO `'.$settings->GetSettingValue ('database_prefix')."emails` VALUES ('', '".$email_addr."', '".$first_name."', '".$last_name."')"; if ($mysql->Query ($query, false)) { $content = 'Your email address has been added'; } else { $content = 'MySQL error: '.mysql_error (); } } else { $content = 'Your email address is not valid'; } I know the regex is a bit over the top but that's not the point. Neither is the PHP, could it be the browser or platform that's causing problems? Quote Link to comment https://forums.phpfreaks.com/topic/149596-solved-firefox-sends-post-data-fine-but-ie-doesnt/ Share on other sites More sharing options...
PFMaBiSmAd Posted March 16, 2009 Share Posted March 16, 2009 Is the email address the first or the only thing being validate and if so, how do you know anything is being received from the form? What is your form code. It might be invalid html and FF ignores the errors and submits data while IE fails to submit any data. Quote Link to comment https://forums.phpfreaks.com/topic/149596-solved-firefox-sends-post-data-fine-but-ie-doesnt/#findComment-785558 Share on other sites More sharing options...
jordanwb Posted March 16, 2009 Author Share Posted March 16, 2009 Here's the page that does validation and all the mysql stuff: <?php include ('backend/settings_manager.php'); include ('backend/mysql.php'); $settings = new SettingsManager ('config.inc.php'); $content = ''; try { $mysql = new MySqlDatabaseEngine ($settings); $action = trim ($_GET['action']); if ($action == 'subscribe') { $first_name = mysql_real_escape_string (trim ($_POST['first_name'])); $last_name = mysql_real_escape_string (trim ($_POST['last_name'])); $email_addr = trim ($_POST['email_addr']); if (preg_match ('#^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.(?:[A-Z]{2}|com|ca|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum)$#i', $email_addr)) { $query = 'INSERT INTO `'.$settings->GetSettingValue ('database_prefix')."emails` VALUES ('', '".$email_addr."', '".$first_name."', '".$last_name."')"; if ($mysql->Query ($query, false)) { $content = 'Your email address has been added'; } else { $content = 'MySQL error: '.mysql_error (); } } else { $content = 'Your email address is not valid'; } } else if ($action == 'unsubscribe') { $email_addr = trim ($_GET['email']); if (preg_match ('#^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.(?:[A-Z]{2}|com|ca|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum)$#i', $email_addr)) { $query = 'DELETE FROM `'.$settings->GetSettingValue ('database_prefix')."emails` WHERE `email_addr`='".$email_addr."'"; if ($mysql->Query ($query, false)) { $content = 'Your email address has been removed'; } else { $content = 'MySQL error: '.mysql_error (); } } else { $content = 'Your email address is not valid'; } } else { $content = 'Invalid action'; } } catch (DatabaseConnectionFailureException $dcfe) { $content = 'The connection to the MySql server could not be created.'; } catch (DatabaseNotFoundException $dnfe) { $content = 'The MySql database could not be found.'; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <link rel="stylesheet" href="style/style.css" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="refresh" content="2;http://<?php print $settings->GetSettingValue ('domain_name').$settings->GetSettingValue ('path_to_root'); ?>" /> <title><?php print $settings->GetSettingValue ('site_title') ?> - Subscribe</title> </head> <body> <div style="padding: 10px; width: 400px; background-color: #E3DBC3; border: 2px solid #6B705F; margin: 15px auto 0px auto; text-align: center;"> <?php print $content; ?> </div> </body> </html> Here's the web form that sends data to the above file: $subscribe_form = '<fieldset>'."\n"; $subscribe_form .= '<legend>Subscribe to Newsletter</legend>'."\n"; $subscribe_form .= '<form action="subscribe.php?action=subscribe" method="post">'."\n"; $subscribe_form .= '<table style="width: 100%; font-size: 10pt;">'."\n"; $subscribe_form .= '<tr>'."\n"; $subscribe_form .= '<td>First Name:</td>'."\n"; $subscribe_form .= '<td><input maxlength="64" name="first_name" size="10" type="text" /></td>'."\n"; $subscribe_form .= '</tr>'."\n"; $subscribe_form .= '<tr>'."\n"; $subscribe_form .= '<td>Last Name:</td>'."\n"; $subscribe_form .= '<td><input maxlength="64" name="last_name" size="10" type="text" /></td>'."\n"; $subscribe_form .= '</tr>'."\n"; $subscribe_form .= '<tr>'."\n"; $subscribe_form .= '<td>Email Address:</td>'."\n"; $subscribe_form .= '<td><input maxlength="128" name="email_addr" size="10" type="text" /></td>'."\n"; $subscribe_form .= '</tr>'."\n"; $subscribe_form .= '<tr>'."\n"; $subscribe_form .= '<td colspan="2"><button name="submit" type="submit" value="1">Subscribe</button></td>'."\n"; $subscribe_form .= '</tr>'."\n"; $subscribe_form .= '</table>'."\n"; $subscribe_form .= '</form>'."\n"; $subscribe_form .= '</fieldset>'."\n"; Quote Link to comment https://forums.phpfreaks.com/topic/149596-solved-firefox-sends-post-data-fine-but-ie-doesnt/#findComment-785768 Share on other sites More sharing options...
PFMaBiSmAd Posted March 16, 2009 Share Posted March 16, 2009 The form is valid and the only difference between IE and FF is that IE sends [submit] => Subscribe while FF sends [submit] => 1 Based on what you have posted, the email address being used does not pass your preg_match statement. You would need to provide information on what email addresses were being used for anyone to be able to help. About the only other possibility is if your actual form page has something else, like nested forms or if you have register_globals on and you have variables overwriting each other that are present for some of the visitors (cookies/session) and not others. It would probably be a good idea if your error messages included the wrong information that did not match ($email_addr in this case) and you should probably log all the information about failed attempts so that you have a record of what is going on. Quote Link to comment https://forums.phpfreaks.com/topic/149596-solved-firefox-sends-post-data-fine-but-ie-doesnt/#findComment-785777 Share on other sites More sharing options...
jordanwb Posted March 16, 2009 Author Share Posted March 16, 2009 I don't have any nested forms, I don't use cookies or sessions in the site ('cept for the admin). I'm not sure if register_globals is on but as you can see in the code I've posted that the variables are initialized to empty or by assignment. I'll try logging and have him retry. Quote Link to comment https://forums.phpfreaks.com/topic/149596-solved-firefox-sends-post-data-fine-but-ie-doesnt/#findComment-785784 Share on other sites More sharing options...
jordanwb Posted March 27, 2009 Author Share Posted March 27, 2009 I figured out what the problem was. In IE7 there's a bug where it will display cached versions of the page instead of the recent one. Having my client clear his cache solved the problem. This also explains why it would work properly in Firefox. Quote Link to comment https://forums.phpfreaks.com/topic/149596-solved-firefox-sends-post-data-fine-but-ie-doesnt/#findComment-795258 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.