Tandem Posted July 16, 2006 Share Posted July 16, 2006 I'm having a problem using switch/case. I've probably missed something obvious, but i can't work it out for the life of me.I'm getting this error:Parse error: parse error, unexpected T_SL in C:\Program Files\Apache Group\Apache2\htdocs\Train_station.php on line 97Here's the relevant code from the page:[code]<?php$travel = $_POST['travel'];if (empty($travel)) {travel_form();}if (!empty($travel)){switch ($travel){case "NY":$sql = mysql_query("UPDATE USERS SET LOCATION='New York' WHERE USERID='$_SESSION[userid]'");/*(line 97)*/print <<<HERE <div class="whitetext" align="center">Welcome to New York!</div>\nHERE;break;case "LA":$sql = mysql_query("UPDATE USERS SET LOCATION='Los Angeles' WHERE USERID='$_SESSION[userid]'");print <<<HERE <div class="whitetext" align="center">Welcome to Los Angeles!</div>\nHERE;break;case "CH":$sql = mysql_query("UPDATE USERS SET LOCATION='Chicago' WHERE USERID='$_SESSION[userid]'");print <<<HERE <div class="whitetext" align="center">Welcome to Chicago!</div>\nHERE;break;case "HN":$sql = mysql_query("UPDATE USERS SET LOCATION='Houston' WHERE USERID='$_SESSION[userid]'");print <<<HERE <div class="whitetext" align="center">Welcome to Houston!</div>\nHERE;break;case "PH":$sql = mysql_query("UPDATE USERS SET LOCATION='Philadelphia' WHERE USERID='$_SESSION[userid]'");print <<<HERE <div class="whitetext" align="center">Welcome to Philadelphia!</div>\nHERE;break;case "DT":$sql = mysql_query("UPDATE USERS SET LOCATION='Detroit' WHERE USERID='$_SESSION[userid]'");print <<<HERE <div class="whitetext" align="center">Welcome to Detroit!</div>\nHERE;break;default:print "Error!\n";}travel_form();}?><?phpfunction travel_form {print <<<HERE<table cellpadding="0" cellspacing="0" width="30%" align="center"><tr><td class="tablehead" colspan="2">TRAVEL TO</td></tr><form type="POST" action="train_station.php"><tr><td class="radio"><input type="radio" name="travel" value="NY"></td><td class="topcity">New York</td></tr><tr><td class="radio"><input type="radio" name="travel" value="LA"></td><td class="city">Los Angeles</td></tr><tr><td class="radio"><input type="radio" name="travel" value="CH"></td><td class="city">Chicago</td></tr><tr><td class="radio"><input type="radio" name="travel" value="HN"></td><td class="city">Houston</td></tr><tr><td class="radio"><input type="radio" name="travel" value="PH"></td><td class="city">Philadelphia</td></tr><tr><td class="radio"><input type="radio" name="travel" value="DT"></td><td class="city">Detroit</td></tr><tr><td class="s" colspan="2"><input type="submit" name="submit" value="Travel!"></form></table>HERE;}?>[/code]In case you're wondering what on earth is going on, i'm building a text-based MMO. This is my project to help me learn php, and i kinda always wanted to do it too :P.This is the relevant code on the train_station.php page. This page changes the user's location to a different city in the game.I've labeled line 97 for you.Would appreciate it if somebody could point out to me what i've done wrong.Thanks in advance-Tandem Quote Link to comment https://forums.phpfreaks.com/topic/14769-switchcase/ Share on other sites More sharing options...
Orio Posted July 16, 2006 Share Posted July 16, 2006 This:<div class="whitetextW align="center">Welcome to New York!</div>\nShould be:<div class="whitetextW[b][color=red]"[/color][/b] align="center">Welcome to New York!</div>\nOrio. Quote Link to comment https://forums.phpfreaks.com/topic/14769-switchcase/#findComment-58964 Share on other sites More sharing options...
Tandem Posted July 16, 2006 Author Share Posted July 16, 2006 I've since changed that, but the error is still happening... Quote Link to comment https://forums.phpfreaks.com/topic/14769-switchcase/#findComment-58965 Share on other sites More sharing options...
Tandem Posted July 16, 2006 Author Share Posted July 16, 2006 Anyone? Quote Link to comment https://forums.phpfreaks.com/topic/14769-switchcase/#findComment-58969 Share on other sites More sharing options...
hitman6003 Posted July 16, 2006 Share Posted July 16, 2006 Using this:[code]print <<<HERE <div class="whitetext" align="center">Welcome to Chicago!</div>nHERE;[/code]is a lot more work that it needs to be, and is probably what is causing your error.Do this instead:[code]echo "<div class="whitetext" align="center">Welcome to Chicago!</div>\n";[/code]You can also format your code to make it more readable when you use the echo statements...or if you don't like echo, you can still use print with the same syntax:[code]print "<div class="whitetext" align="center">Welcome to Chicago!</div>\n";[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14769-switchcase/#findComment-58972 Share on other sites More sharing options...
Tandem Posted July 16, 2006 Author Share Posted July 16, 2006 Still getting an error.I had it with the syntax you said, before, but i changed it to the '<<HERE' etc in the hope that it would somehow fix the problem.I'm getting a different error now though, perhaps you might be able to tell whats wrong from that. It's:Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in C:\Program Files\Apache Group\Apache2\htdocs\Train_station.php on line 103Heres a few line of the relevant code:[code]if (!empty($travel)){$location_check = mysql_query("SELECT LOCATION FROM USERS WHERE USERID='$_SESSION[userid]'");$location = mysql_result($location_check,0);print "You are currently in $location\n";switch ($travel){case "NY":$sql = mysql_query("UPDATE USERS SET LOCATION='New York' WHERE USERID='$_SESSION[userid]'");/*(line 103)*/echo "<div class="whitetext" align="center">Welcome to New York!</div>\n";break;[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14769-switchcase/#findComment-58973 Share on other sites More sharing options...
hitman6003 Posted July 16, 2006 Share Posted July 16, 2006 You have to escape the double quotes when they are inside of double quotes(I missed that you had them in there when I posted above)...or wrap the statement in single quotes rather than double:Either[code]echo "<div class=\"whitetext\" align=\"center\">Welcome to New York!</div>\n";[/code]or[code]echo '<div class="whitetext" align="center">Welcome to New York!</div>\n';However, with the latter it will not substitute a new line for \n, it will put \n in the output.So the latter should be:[code]echo '<div class="whitetext" align="center">Welcome to New York!</div>' . "\n";[/code][/code] Quote Link to comment https://forums.phpfreaks.com/topic/14769-switchcase/#findComment-58976 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.