0

i am trying a case statement that will input different results based on the town a user enters in a form .the code in the form is

<html>
<body>
<form action="relay.php" method="get">
town:<input type="text" name="town" />
<input type="submit" />
</form>
</body>
</html

while that one for case is

<?php
$destination="$_GET["town"]";
echo "Travelling to $destination<br />";
switch($destination){
case "las vegas ":
echo "bring an extra $500";
break;
case "amsterdam":
echo "bring an open mind";
break;
case "egypt":
echo "bring 15 bottles of spf 50 sunscreen";
break;
case "tokyo":
echo "bring lots of monet";
break;
case "caribbean islands":
echo "bring a swimsuit";
break;
default:
echo "bring lots of underwear";
break;
}
?>

i am having the error "Parse error: syntax error, unexpected '"', expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\relay.php on line 2"

4
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by _Rade
0

Problem is here:

$destination="$_GET["town"]";

- Anything starting with $_CAPS[] is a PHP array. Using quotes like this: "data here" declares a string. So if you were to echo "$_GET["town"]"; you will output the text "$_GET[", before PHP becoming confused by the remaining part - town"]".

You are trying to output the value corresponding to the key "town" inside the array $_GET, so you need to change line 2 to:

$destination=$_GET["town"];

Let us know how it goes :)

Edited by _Rade: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.