Jump to content

[SOLVED] Captcha processing problem


Lambneck

Recommended Posts

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
Share on other sites

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
Share on other sites

<?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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.