-3

I have this PHP code:

<?php
$redirectURL = 'contests-representative-of-the-year-thankyou.php';
$email_to = 'alex@theadamgrp.com';
$subject = 'Submission Form';
#### DO NOT EDIT BELOW THIS LINE ####
require_once dirname(__FILE__) . '/securimage.php';
$securimage = new Securimage();
$captcha = (isset($_REQUEST['ct_captcha'])) ? $_REQUEST['ct_captcha'] :
'';

if ($securimage->check($captcha) == false)   {
    die ('<p style="margin:30px 0 0 0; font-weight:bold; font-size:16px;">Invalid security code entered. Please <a href="javascript:history.go(-1);">click here</a> to go back.</p>');
}

$message = 'This form submission was received at '.date('n/j/Y g:i A').': '."\n\n";
foreach ($_POST as $key=>$value){
    $message .= "\n\n".str_replace('_', ' ', $key).": \n".$value;
}

$message .= "\n\nIP: ".$_SERVER['REMOTE_ADDR'];
mail($email_to, $subject, $message, 'From: no-reply@email.com');
?>

When I insert this into my web page, it "deletes" the rest of my code below. I'm suppose to have a footer below it with links and everything. This is what I have below it:

</div>
</div>
<?php include("subpage-bar.php"); ?>
</div>
</div>
</div>
<?php include("footer.php"); ?>
</body>

Is there any reason why my PHP code above would delete everything else I have coded below it? Here is a link to view the source, if you want to visually see what O mean. I can't figure out what the problem is. Any help is appreciated.

Alex Kittavong
  • 193
  • 1
  • 2
  • 13
  • [It usually means that an error occurred and error reporting is turned off.](http://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php/12772851#12772851) – Sammitch Apr 10 '13 at 19:44
  • You need to debug your code: [How to get useful error messages in PHP?](http://stackoverflow.com/q/845021/1409082) – Jocelyn Apr 10 '13 at 20:20

1 Answers1

1

change die() into echo

So change

die ('<p style="margin:30px 0 0 0; font-weight:bold; font-size:16px;">Invalid security code entered. Please <a href="javascript:history.go(-1);">click here</a> to go back.</p>');

into

echo '<p style="margin:30px 0 0 0; font-weight:bold; font-size:16px;">Invalid security code entered. Please <a href="javascript:history.go(-1);">click here</a> to go back.</p>';

(so echo without the parens ())

edit

For the working catha change this:

if ($securimage->check($captcha) == false)   {
    die ('<p style="margin:30px 0 0 0; font-weight:bold; font-size:16px;">Invalid security code entered. Please <a href="javascript:history.go(-1);">click here</a> to go back.</p>');
}

$message = 'This form submission was received at '.date('n/j/Y g:i A').': '."\n\n";
foreach ($_POST as $key=>$value){
    $message .= "\n\n".str_replace('_', ' ', $key).": \n".$value;
}

$message .= "\n\nIP: ".$_SERVER['REMOTE_ADDR'];
mail($email_to, $subject, $message, 'From: no-reply@email.com');

into this:

if ($securimage->check($captcha) == false)   {
    echo '<p style="margin:30px 0 0 0; font-weight:bold; font-size:16px;">Invalid security code entered. Please <a href="javascript:history.go(-1);">click here</a> to go back.</p>';
} else {
    $message = 'This form submission was received at '.date('n/j/Y g:i A').': '."\n\n";
    foreach ($_POST as $key=>$value){
        $message .= "\n\n".str_replace('_', ' ', $key).": \n".$value;
    }

    $message .= "\n\nIP: ".$_SERVER['REMOTE_ADDR'];
    mail($email_to, $subject, $message, 'From: no-reply@email.com');
}
nl-x
  • 11,762
  • 7
  • 33
  • 61
  • Thanks. That does work, but now its not validating my captcha. – Alex Kittavong Apr 10 '13 at 19:44
  • @AlexKittavong Look at the Edit I placed in my answer. What I did is place the rest of the code after the captcha `if(){}`, inside an `else{}`. – nl-x Apr 10 '13 at 19:51
  • Getting very close. it validates captcha and submits the form, but it does take me to my thank you page that I have redirected to: $redirectURL = 'contests-representative-of-the-year-thankyou.php'; – Alex Kittavong Apr 10 '13 at 19:59
  • @AlexKittavong You mean is does **n't** take you to the page? But that is probably because you are doing nothing with `$redirectURL`. You only set a php file name in it. But you never use that variable in the code you pasted. – nl-x Apr 10 '13 at 20:10
  • Yes sorry, it does not take me to the page. the &redirectURL did take me to my thank you page before i replaced the last bit of code you sent me. – Alex Kittavong Apr 10 '13 at 20:16
  • @AlexKittavong Can you show me your entire file now ? – nl-x Apr 10 '13 at 20:19
  • No problem, http://www.mediafire.com/?8s7364zg0n5f93p That's the download link. Thanks for all the help! – Alex Kittavong Apr 10 '13 at 20:22
  • @AlexKittavong Nope. you are doing absolutely nothing with `$redirectURL`. What you can do is something like this right under `mail()` before you close the `else`: `echo "";` – nl-x Apr 10 '13 at 20:29
  • NICE! That worked! I really appreciate all the help! – Alex Kittavong Apr 10 '13 at 20:34