Page 1 of 1

validating form input and then forwarding

Posted: Fri Sep 17, 2010 11:30 pm
by torads
Here's what Im looking to do and have had no luck getting it to work using my limited experience.

I have a form with 3 input text fields where the visitor would have to enter three 6 digit codes. They would find these codes on other pages on my website. once they have entered the codes correctly and clicked submit I would like them to be forwarded to the download page.


I have assigned the correct codes to variables $realcode1 $realcode2 and $realcode3 and then tried to compare them to the input data from the form.
Here's some code I wrote to attempt this.

I have no issue with the form,

form action="handle_form.php"

the contents of handle_form.php

Code: Select all

<?php

$realcode1 = 723598;
$realcode2 = 193598;
$realcode3 = 887362;
$code1 = htmlspecialchars($_GET['code1']);
$code2 = htmlspecialchars($_GET['code2']);
$code3 = htmlspecialchars($_GET['code3']);

if ($code1 == $realcode1 && $code2 == $realcode2 && $code3 == $realcode3) {
    header('Location: my download link')
    
    } else {
    
    echo "You haven't entered the correct codes.";
    
    }

exit();
?>
I have been searching google and think i am mixing stuff together that is not needed. I would like it to be secure as well so any help with this would also be good.

Ideas or suggestions anyone?

Re: validating form input and then forwarding

Posted: Fri Sep 17, 2010 11:44 pm
by torads
I have made some changes to make it work. I have got rid of the errors but instead of going to the download page it is loading the handle_form.php link??
where am I wrong besides the whole thing, lol

Code: Select all

<?php

if (isset($_POST['submitted'])) {


$realcode1 = 723598;
$realcode2 = 193598;
$realcode3 = 887362;
$code1 = htmlspecialchars($_POST['code1']);
$code2 = htmlspecialchars($_POST['code2']);
$code3 = htmlspecialchars($_POST['code3']);

if ($code1 == $realcode1 && $code2 == $realcode2 && $code3 == $realcode3) {
    header('Location: my download page url');
    
    } else {
    
    echo "please enter the correct codes.";
    
    }
}

?>