Lambneck Posted September 24, 2008 Share Posted September 24, 2008 I am having trouble with my form processing script. When my forms are submitted i just get a blank page. form processor: <?php ini_set('error_reporting', E_ALL); function check_input($data, $problem='') { $data = mysql_real_escape_string(trim(strip_tags(htmlspecialchars($data))); if ($problem && strlen($data) == 0) { show_error($problem); } return $data; } function show_error($myError) { ?> <html> <body> <b>Please correct the following error:</b><br /> <?php echo $myError; ?> </body> </html> <?php exit(); } if (isset($_POST['submit'])){ //Code for processing the form: $db_host = 'xxxx'; $db_user = 'xxxx'; $db_pwd = 'xxxx'; $database = 'xxxx'; $table = 'xxxx'; $connect = mysql_connect($db_host, $db_user, $db_pwd); mysql_select_db($database); $country = check_input($_POST['country'],"Select a country."); $compname = check_input($_POST['company_name'],"Enter your company name."); $email = htmlspecialchars($_POST['email']); if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email)){ show_error('E-mail address not valid.'); } $subject = check_input($_POST['subject'],"Enter a subject"); $message = check_input($_POST['message'],"Enter your advertisement."); $submission_date = date("l M dS, Y, H:i:s"); $ip = getenv ('REMOTE_ADDR'); $insert = mysql_query("INSERT INTO $table (col_1, col_2, col_3, col_4, col_5, submission_date, ip_address) VALUES ('$country', '$compname', '$email', '$subject','$message', '$submission_date','$ip')")or show_error(mysql_error()); } header('Location: thankYou.html'); exit(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/125558-solved-form-processing/ Share on other sites More sharing options...
JasonLewis Posted September 24, 2008 Share Posted September 24, 2008 The best debug method is to place echo's in places to see where the script gets to before it stops working. Also, ensure that the values you submitted are being set properly by echoing them out or dumping the $_POST variable. Quote Link to comment https://forums.phpfreaks.com/topic/125558-solved-form-processing/#findComment-649181 Share on other sites More sharing options...
Lambneck Posted September 24, 2008 Author Share Posted September 24, 2008 since my code is fairly perfect, i figure the problem must be in the database... no? again im new at this. Field Type Collation Attributes Null Default Extra Action submission_id mediumint( UNSIGNED No auto_increment Browse distinct values Change Drop Primary Unique Index Fulltext col_1 varchar(50) latin1_swedish_ci No Browse distinct values Change Drop Primary Unique Index Fulltext col_2 varchar(50) latin1_swedish_ci No Browse distinct values Change Drop Primary Unique Index Fulltext col_3 varchar(50) latin1_swedish_ci No Browse distinct values Change Drop Primary Unique Index Fulltext col_4 varchar(150) latin1_swedish_ci No Browse distinct values Change Drop Primary Unique Index Fulltext col_5 mediumblob BINARY No Browse distinct values Change Drop Primary Unique Index Fulltext submission_date varchar(50) latin1_swedish_ci No Browse distinct values Change Drop Primary Unique Index Fulltext ip_address varchar(50) latin1_swedish_ci No Browse distinct values Change Drop Primary Unique Index Fulltext is_finalized enum('yes', 'no') latin1_swedish_ci No Browse distinct values Change Drop Primary Unique Index Fulltext Quote Link to comment https://forums.phpfreaks.com/topic/125558-solved-form-processing/#findComment-649347 Share on other sites More sharing options...
jonsjava Posted September 24, 2008 Share Posted September 24, 2008 since my code is fairly perfect, you forgot a ")" on line 6: <?php ini_set('error_reporting', E_ALL); function check_input($data, $problem='') { $data = mysql_real_escape_string(trim(strip_tags(htmlspecialchars($data)))); if ($problem && strlen($data) == 0) { show_error($problem); } return $data; } function show_error($myError) { ?> <html> <body> <b>Please correct the following error:</b><br /> <?php echo $myError; ?> </body> </html> <?php exit(); } if (isset($_POST['submit'])){ //Code for processing the form: $db_host = 'xxxx'; $db_user = 'xxxx'; $db_pwd = 'xxxx'; $database = 'xxxx'; $table = 'xxxx'; $connect = mysql_connect($db_host, $db_user, $db_pwd); mysql_select_db($database); $country = check_input($_POST['country'],"Select a country."); $compname = check_input($_POST['company_name'],"Enter your company name."); $email = htmlspecialchars($_POST['email']); if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email)){ show_error('E-mail address not valid.'); } $subject = check_input($_POST['subject'],"Enter a subject"); $message = check_input($_POST['message'],"Enter your advertisement."); $submission_date = date("l M dS, Y, H:i:s"); $ip = getenv ('REMOTE_ADDR'); $insert = mysql_query("INSERT INTO $table (col_1, col_2, col_3, col_4, col_5, submission_date, ip_address) VALUES ('$country', '$compname', '$email', '$subject','$message', '$submission_date','$ip')")or show_error(mysql_error()); } header('Location: thankYou.html'); exit(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/125558-solved-form-processing/#findComment-649400 Share on other sites More sharing options...
Lambneck Posted September 24, 2008 Author Share Posted September 24, 2008 well i did say "fairly" perfect. I appreciate the input, however it hasn't changed the result... i still get a blank page when form after form is submitted. ??? Quote Link to comment https://forums.phpfreaks.com/topic/125558-solved-form-processing/#findComment-649901 Share on other sites More sharing options...
jjacquay712 Posted September 24, 2008 Share Posted September 24, 2008 your code makes me want to eat my heart out Quote Link to comment https://forums.phpfreaks.com/topic/125558-solved-form-processing/#findComment-649902 Share on other sites More sharing options...
Lambneck Posted September 24, 2008 Author Share Posted September 24, 2008 just so we're clear, that was meant as an ironic joke. actually i don't know what i'm doing, as this is my first attempt at using php. Quote Link to comment https://forums.phpfreaks.com/topic/125558-solved-form-processing/#findComment-649955 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.