Php GET problem, Please assist?

DeWire

New member
When i use the form in my php script called sticky.php , and enter data, the URL becomes " /<?firstname=John&lastname=Smith&wines[]=shiraz&wines[]=merlot&button=Submit+Name " , which doesnt function and shows an error 403 [access forbidden ] .

But if I change the '<' to sticky.php , it functions and works correctly. Can anyone tell me how to fix this ?

My code is :
<?php

if (isset($_REQUEST['button']))
{
$error = validate_form();
if ($error)
{
display_form_page ($error);
}
else
{
display_output_page();
}
}
else
{
display_form_page('');
}
?>

<?php
function display_form_page($error)
{
$self = $_SERVER['PHP_SELF'];
$first_name = isset($_REQEST['firstname']) ? $_REQUEST['firstname'] : '';
$last_name = isset($_REQEST['lastname']) ? $_REQUEST['lastname'] : '';
$wines = isset($_REQEST['wines']) ? $_REQUEST['wines'] : '';
?>
<html>
<head>
<link rel="stylesheet">
<title>Sticky Checkboxes</title>
<style type="text/css">
.error{ color:#ff0000;}
</style>
</head>
<body>
<h1>Sticky Checkboxes</h1>


<?php
if($error)
{
echo "<p>$error</p>\n";
}
?>

<form action="<?phpecho $self ?>" method="GET">
<p>First name: <input class ="input" type="text" name="firstname"
value ="<?php echo $first_name?>"</p>
<p>Last name: <input class="input" type="text" name="lastname"
value ="<?php echo $last_name?>"</p>
<p>Chose your favourite wines:</p>
Shiraz <input type ="checkbox" name="wines[]"value="shiraz" <?php
check($wines,"shiraz")?>>

Merlot <input type ="checkbox" name="wines[]"value="merlot" <?php
check($wines,"merlot")?>>

Chianti <input type ="checkbox" name="wines[]"value="chianti" <?php
check($wines,"chianti")?>>

<p><input type="submit" name="button" value="Submit Name"></p>
</form>
</body>
</html>
<?php
}
?>


<?php
function check($wines, $val)
{
if (is_array($wines) and in_aray($val,$wines))
{
echo 'checked = "checked"';
}
}
?>


<?php
function validate_form()
{
$first_name = trim($_REQUEST['firstname']);
$last_name = trim($_REQUEST['lastname']);
$wines = isset($_REQUEST['firstname']) ? $_REQUEST['wines'] : '';

$error='';
$reg_exp = "/^[a-zA-Z'-]+$/";
if (! preg_match($reg_exp, $first_name))
{
$error .=
"<span class=\"error\">First name is invalid (letters, hyphens, ', only)</span><br>";
}
if (! preg_match($reg_exp, $last_name))
{
$error .=
"<span class=\"error\">Last name is invalid (letters, hyphens, ', only)</span><br>";
}
if (! is_array($wines))
{
$error.= "<span class=\"error\">You must select at least one wine</span></br>";
}
return $error; }


function display_output_page()
{
$first_name = trim($_REQUEST['firstname']);
$last_name = trim($_REQUEST['lastname']);
$wines = isset($_REQUEST['wines']) ? $_REQUEST['wines'] : '' ;
?>
<html>
<head><title>Form Results</title></head>
<body>
<h1>Form Results</h1></body>
</html>
<?php

echo "Hello $first_name $last_name</br>\n";
if (is_array($wines))
{
echo "Favourite wines are ";
foreach ($wines as $wine)
{
echo $wine. " ";
}

}}
?>


Thanks for all help received.

Dave
 
Back
Top