Lambneck Posted September 22, 2008 Share Posted September 22, 2008 since i wrapped the captcha processing code around my form processing code i come up with blank pages when form is submitted. can anyone see what Im doing wrong here? Form Processor: <?php ini_set('error_reporting', E_ALL); session_start(); if( isset($_POST['submit'])) { if( $_SESSION['security_code'] == $_POST['security_code'] && !empty($_SESSION['security_code'] ) ) { //Code for processing the form: $db_host = 'xxxxxxx'; $db_user = 'xxxxxxx'; $db_pwd = 'xxxxxxx'; $database = 'xxxxxxx'; $table = 'xxxxxxx'; mysql_connect($db_host, $db_user, $db_pwd); mysql_select_db($database); if (isset($_POST['submit'])) { $name = check_input($_POST['name'],"Please enter your name."); $email = htmlspecialchars($_POST['email']); if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email)) { die("E-mail address not valid"); } $subject = check_input($_POST['subject'],"Please enter a subject."); $message = check_input($_POST['message'],"Please enter your resume."); $submission_date = date("l M dS, Y, H:i:s"); $ip = getenv ('REMOTE_ADDR'); mysql_query("INSERT INTO $table (col_2, col_3, col_4, col_5, submission_date, ip_address) VALUES ('$name', '$email', '$subject', '$message', '$submission_date', '$ip')")or die(mysql_error()); $user = $_POST['name']; } function check_input($data, $problem='') { $data = trim($data); $data = stripslashes($data); $data = 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(); } header('Location: thankYouForResume.html'); unset($_SESSION['security_code']); exit(); } else { //Code for showing an error message here: echo 'Sorry, you have provided an invalid security code'; } ?> Link to comment https://forums.phpfreaks.com/topic/125381-solved-captcha-processing-problem/ Share on other sites More sharing options...
PFMaBiSmAd Posted September 23, 2008 Share Posted September 23, 2008 The code contains the following fatal parse error because there are not enough } - Parse error: syntax error, unexpected $end in your_file.php on line 80 You need to go through your code and make sure there are matching {} every place you intended them to be. When developing php code or debugging php code, you should do it on a local development system where error_reporting is set to E_ALL and display_errors is set to ON in your php.ini to get php to help you. Link to comment https://forums.phpfreaks.com/topic/125381-solved-captcha-processing-problem/#findComment-648248 Share on other sites More sharing options...
Adam Posted September 23, 2008 Share Posted September 23, 2008 <?php session_start(); ini_set('error_reporting', E_ALL); function check_input($data, $problem='') { $data = trim($data); $data = stripslashes($data); $data = 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']) ) { if($_SESSION['security_code'] != $_POST['security_code'] && empty($_SESSION['security_code']) ) { show_error('Sorry, you have provided an invalid security code'); } //Code for processing the form: $db_host = 'xxxxxxx'; $db_user = 'xxxxxxx'; $db_pwd = 'xxxxxxx'; $database = 'xxxxxxx'; $table = 'xxxxxxx'; $connect = mysql_connect($db_host, $db_user, $db_pwd); mysql_select_db($database); $name = check_input($_POST['name'], "Please enter your name."); $email = htmlspecialchars($_POST['email']); if (! preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email) ) { show_error('E-mail address not valid.'); } $subject = check_input($_POST['subject'], "Please enter a subject."); $message = check_input($_POST['message'], "Please enter your resume."); $submission_date = date("l M dS, Y, H:i:s"); $ip = getenv("REMOTE_ADDR"); $insert = mysql_query("INSERT INTO $table (col_2, col_3, col_4, col_5, submission_date, ip_address) VALUES ('$name', '$email', '$subject', '$message', '$submission_date', '$ip')") or show_error(mysql_error()); // whats this for? $user = $_POST['name']; } header('Location: thankYouForResume.html'); unset($_SESSION['security_code']); exit(); ?> try that... just rearranged the code to be easier to understand and altered one or two small things.. Adam Link to comment https://forums.phpfreaks.com/topic/125381-solved-captcha-processing-problem/#findComment-648275 Share on other sites More sharing options...
Lambneck Posted September 23, 2008 Author Share Posted September 23, 2008 MrAdam, Thank you! It works! Link to comment https://forums.phpfreaks.com/topic/125381-solved-captcha-processing-problem/#findComment-648288 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.