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"

Im not 100% but i think line 23 shouldnt be there

Hi,
Remove the quotes from line 2 and make it as below,

$destination=$_GET["town"];

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 :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.