aaronk7 Posted May 22, 2007 Share Posted May 22, 2007 Hello there, I am getting this error when i go to my php page: Parse error: parse error, unexpected T_STRING The code near line 98 is this: line96: $sql1 = $_GET[game]; line97: $sqltogether = g_$sql1; line98: $sql = "select * from $sqltogether where team = '1'"; line99: line100: $query = mysql_query($sql); line101: line102: while($row = mysql_fetch_array($query)) { line103: echo "".$row['player']."<br>"; line104: } If someone could help me figure out how to fix this i would appreciate it alot. Thanks in advanced. Quote Link to comment https://forums.phpfreaks.com/topic/52512-solved-parse-error-parse-error-unexpected-t_string/ Share on other sites More sharing options...
taith Posted May 22, 2007 Share Posted May 22, 2007 $sqltogether = g_$sql1; theres your problem... g_? Quote Link to comment https://forums.phpfreaks.com/topic/52512-solved-parse-error-parse-error-unexpected-t_string/#findComment-259108 Share on other sites More sharing options...
trq Posted May 22, 2007 Share Posted May 22, 2007 $sqltogether = g_$sql1; should be... $sqltogether = 'g_'.$sql1; You also have an error on line 103, when you get to it. echo $row['player']; Quote Link to comment https://forums.phpfreaks.com/topic/52512-solved-parse-error-parse-error-unexpected-t_string/#findComment-259109 Share on other sites More sharing options...
taith Posted May 22, 2007 Share Posted May 22, 2007 You also have an error on line 103, when you get to it. echo $row['player']; not necessarily... it seems its echo $row['player']."<br>"; but without the code tags, it looks broke ;-) Quote Link to comment https://forums.phpfreaks.com/topic/52512-solved-parse-error-parse-error-unexpected-t_string/#findComment-259113 Share on other sites More sharing options...
aaronk7 Posted May 22, 2007 Author Share Posted May 22, 2007 thanks for the quick reply, ok so i have now made them changes but the error is still appearing Parse error: parse error, unexpected T_STRING in /home/www/lazertag.freehostia.com/games.php on line 98 line96: $sql1 = $_GET[game]; line97: $sqltogether = 'g_'.$sql1; line98: $sql = "select * from $sqltogether where team = '1'"; line99: line100: $query = mysql_query($sql); line101: line102: while($row = mysql_fetch_array($query)) { line103: echo $row['player']; line104: } I have looked on other forums and people are getting the same error when they are using : $_GET[game]; Can anyone see what is wrong or have another approach to this code? Quote Link to comment https://forums.phpfreaks.com/topic/52512-solved-parse-error-parse-error-unexpected-t_string/#findComment-259118 Share on other sites More sharing options...
kenrbnsn Posted May 22, 2007 Share Posted May 22, 2007 Try rewriting your code like this: <?php $sql = "select * from g_" . $_GET['game'] . " where team = '1'"; ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/52512-solved-parse-error-parse-error-unexpected-t_string/#findComment-259122 Share on other sites More sharing options...
aaronk7 Posted May 22, 2007 Author Share Posted May 22, 2007 The error is still coming up with this line: $sql = "select * from g_" . $_GET['game'] . " where team = '1'"; Is there any other solutions? Quote Link to comment https://forums.phpfreaks.com/topic/52512-solved-parse-error-parse-error-unexpected-t_string/#findComment-259129 Share on other sites More sharing options...
kenrbnsn Posted May 22, 2007 Share Posted May 22, 2007 Please post more of your script before the line in question. Please surround your code with tags. Ken Quote Link to comment https://forums.phpfreaks.com/topic/52512-solved-parse-error-parse-error-unexpected-t_string/#findComment-259136 Share on other sites More sharing options...
MadTechie Posted May 22, 2007 Share Posted May 22, 2007 try <?php $sql1 = $_GET['game']; $sqltogether = "g_".$sql1; $sql = "select * from $sqltogether where team = '1'"; $query = mysql_query($sql); while( $row = mysql_fetch_array($query) ) { echo $row['player']; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/52512-solved-parse-error-parse-error-unexpected-t_string/#findComment-259137 Share on other sites More sharing options...
aaronk7 Posted May 22, 2007 Author Share Posted May 22, 2007 Ok when i use MadTechie's idea i get this error: Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/www/lazertag.freehostia.com/games.php on line 97, which i believe is the same but with 1 extra error. Basically i am developing a code/script to recieve a value from the address "$_GET[game]" and opening up the table which is called g_(then that value, so g_ is like a prefix, once i have got that table i would like to take all the infomation out of it and display it. If anyone can come up with a solution on how to get the value from the address (http://example.com/test.php?value=1) and then open the table g_(that value gotten) and recieve all the infomation from there. That is what i am trying to do. All the code above is where i am connecting to the mysql database and verifing some user requirements like login. Thanks for all of your quick reply's, this site is the best! Quote Link to comment https://forums.phpfreaks.com/topic/52512-solved-parse-error-parse-error-unexpected-t_string/#findComment-259142 Share on other sites More sharing options...
MadTechie Posted May 22, 2007 Share Posted May 22, 2007 your need to post some more code at my code looks fine.. unless you added the <?php and ?> Quote Link to comment https://forums.phpfreaks.com/topic/52512-solved-parse-error-parse-error-unexpected-t_string/#findComment-259151 Share on other sites More sharing options...
aaronk7 Posted May 22, 2007 Author Share Posted May 22, 2007 ok i will post the code of all the stuff i have in my file. I will trust you guys Again, thanks for helping me out! Here it is: <? ob_start(); include("config.php"); if (!$_GET[date]&&!$_GET[game]) { $getuser = mysql_query("SELECT * from dates ORDER BY `ID` DESC"); while ($user = mysql_fetch_array($getuser)) { // gets all the users information. echo ("<a href=\"games.php?date=$user[iD]\">$user[Date]</a> <br />\n"); // links to a page to view the user's profile. //echo ("<a href=\"games.php\">Go Back</a>" } } ELSEIF ($_GET[date]) { $getuser = mysql_query("SELECT * from games where DateID = '$_GET[date]' ORDER BY `ID` DESC"); while ($user = mysql_fetch_array($getuser)) { // gets all the users information. echo ("<a href=\"games.php?game=".$user['ID']."\">$user[Name]</a> <br />\n"); // links to a page to view the user's profile. //echo ("<a href=\"games.php\">Go Back</a>" } } ELSE { $gameinfo = mysql_query("SELECT * from games where ID = '$_GET[game]'"); $usernum = mysql_num_rows($gameinfo); if ($usernum == 0) { echo ("Game Not Found"); } else { $game = mysql_query("SELECT * from games where ID = '$_GET[game]' ORDER BY `ID` DESC"); $gamename = $game[Name]; $gamewinner = $game[winningteamorplayer]; $gametemp = $_GET['game']; $gamedatateam1 = mysql_query("SELECT * from g_$gametemp where team = '1' "); $gamedatateam2 = mysql_query("SELECT * from g_$gametemp where team = '2' "); $gamedatateam3 = mysql_query("SELECT * from g_$gametemp where team = '3' "); echo(" <table> <td> <tr> Game Name: <?php echo(".$gamename."); ?> </tr> </td> <td> <tr> Overall Winner(Team or Player): <?php echo(".$gamewinner."); ?> </tr> </td> </table> <br> <table> <tr> <td>Rank</td> <td>Team 1</td> <td>Rank</td> <td>Team 2</td> <td>Rank</td> <td>Team 3</td> </tr> <tr> <td> <?php while ($team1 = mysql_fetch_array($gamedatateam1)) { echo ("-".$team1[rank].\"<br>\"); } ?> </td> <td> <tr> <?php $sql = "select * from g_" . $_GET['game'] . " where team = '1'"; $query = mysql_query($sql); while($row = mysql_fetch_array($query)) { echo $row['player']."<br>"; } ?> </tr> <td> <?php while ($team2 = mysql_fetch_array($gamedatateam2)) { echo ("$team2[rank]<br>"); } ?> </td> <td> <?php while ($team1 = mysql_fetch_array($gamedatateam2)) { echo ("<a href=\"games.php?game=$_GET[game]&user=$team2[iD]\">$team2[player]</a><br>"); } ?> </td> <td> <?php while ($team3 = mysql_fetch_array($gamedatateam3)) { echo ("$team3[rank]<br>"); } ?> </td> <td> <?php while ($team1 = mysql_fetch_array($gamedatateam3)) { echo ("<a href=\"games.php?game=$_GET[game]&user=$team3[iD]\">$team3[player]</a><br>"); } ?> </td> </table> "); } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/52512-solved-parse-error-parse-error-unexpected-t_string/#findComment-259153 Share on other sites More sharing options...
kenrbnsn Posted May 22, 2007 Share Posted May 22, 2007 The problem is probably coming from this line: <?php echo ("-".$team1[rank]."<br>\"); ?> you are escaping the double quote with the backslash, so PHP is ignoring the double quote as the end of the string. It doesn't find another double quote until the start of the $sql string. That double quote terminates the last string and then PHP sees something it doesn't understand and issues the error message. Remove the backslash and you should be OK here. BTW, you should alway quote strings that are used as array indices. Ken Quote Link to comment https://forums.phpfreaks.com/topic/52512-solved-parse-error-parse-error-unexpected-t_string/#findComment-259156 Share on other sites More sharing options...
aaronk7 Posted May 22, 2007 Author Share Posted May 22, 2007 Ok, thanks very much for that, i am just getting 1 more error: Parse error: parse error, unexpected $ This is at the very end where ?> is! Could someone solve this very last error. Thank You. Thanks alot for your answer which solved the other problem. Quote Link to comment https://forums.phpfreaks.com/topic/52512-solved-parse-error-parse-error-unexpected-t_string/#findComment-259166 Share on other sites More sharing options...
taith Posted May 22, 2007 Share Posted May 22, 2007 wow... um... "); } } } ?> that makes no sense... a) you cant loop inside of a variable, b) prolly just cut that off Quote Link to comment https://forums.phpfreaks.com/topic/52512-solved-parse-error-parse-error-unexpected-t_string/#findComment-259167 Share on other sites More sharing options...
kenrbnsn Posted May 22, 2007 Share Posted May 22, 2007 At the end of the posted code you have <?php while ($team1 = mysql_fetch_array($gamedatateam3)) { echo ("<a href=\"games.php?game=$_GET[game]&user=$team3[iD]\">$team3[player]</a><br>"); } ?> </td> </table> "); } } } ?> It looks like you gave some extra lines of code or you forgot to go back into PHP mode. Ken Quote Link to comment https://forums.phpfreaks.com/topic/52512-solved-parse-error-parse-error-unexpected-t_string/#findComment-259168 Share on other sites More sharing options...
aaronk7 Posted May 22, 2007 Author Share Posted May 22, 2007 so what should i do delete that part: "); } } } ?> If i do it comes up with the same error. What should i do with thsi code? Quote Link to comment https://forums.phpfreaks.com/topic/52512-solved-parse-error-parse-error-unexpected-t_string/#findComment-259175 Share on other sites More sharing options...
kenrbnsn Posted May 22, 2007 Share Posted May 22, 2007 Although you marked this solved, I decided to look at your code in more detail. The following is your code with no syntax errors, but I think you have some logic errors in it: <?php ob_start(); include("config.php"); if (!$_GET['date']&&!$_GET['game']) { $getuser = mysql_query("SELECT * from dates ORDER BY `ID` DESC"); while ($user = mysql_fetch_array($getuser)) // gets all the users information. echo ("<a href=\"games.php?date=$user[iD]\">$user[Date]</a> <br />\n"); } elseif (isset($_GET['date'])) { $getuser = mysql_query("SELECT * from games where DateID = '$_GET[date]' ORDER BY `ID` DESC"); while ($user = mysql_fetch_array($getuser)) // gets all the users information. echo '<a href="games.php?game=' . $user['ID'] . '">' . $user['Name'] . "</a> <br />\n"; } else { $gameinfo = mysql_query("SELECT * from games where ID = '" . $_GET['game'] . "'"); $usernum = mysql_num_rows($gameinfo); if ($usernum == 0) echo ("Game Not Found"); else { $game = mysql_query("SELECT * from games where ID = '$_GET[game]' ORDER BY `ID` DESC"); $gamename = $game['Name']; $gamewinner = $game['winningteamorplayer']; $gametemp = $_GET['game']; $gamedatateam1 = mysql_query("SELECT * from g_$gametemp where team = '1' "); $gamedatateam2 = mysql_query("SELECT * from g_$gametemp where team = '2' "); $gamedatateam3 = mysql_query("SELECT * from g_$gametemp where team = '3' "); ?> <table> <td> <tr> Game Name: <?php echo $gamename ?> </tr> </td> <td> <tr> Overall Winner(Team or Player): <?php echo$gamewinner; ?> </tr> </td> </table> <br> <table> <tr> <td>Rank</td> <td>Team 1</td> <td>Rank</td> <td>Team 2</td> <td>Rank</td> <td>Team 3</td> </tr> <tr> <td> <?php while ($team1 = mysql_fetch_array($gamedatateam1)) echo "-".$team1[rank]."<br>"; ?> </td> <td> <tr> <?php $sql = "select * from g_" . $_GET['game'] . " where team = '1'"; $query = mysql_query($sql); while($row = mysql_fetch_assoc($query)) echo $row['player']."<br>"; ?> </tr> <td> <?php while ($team2 = mysql_fetch_assoc($gamedatateam2)) echo $team2['rank'] . "<br>"; ?> </td> <td> <?php while ($team1 = mysql_fetch_assoc($gamedatateam2)) echo '<a href="games.php?game=' . $_GET['game'] . '&user=' . $team2['ID'] . '">' . $team2['player'] . "</a><br>"; ?> </td> <td> <?php while ($team3 = mysql_fetch_assoc($gamedatateam3)) echo $team3['rank'] . "<br>"; ?> </td> <td> <?php while ($team1 = mysql_fetch_assoc($gamedatateam3)) echo '<a href="games.php?game=' . $_GET['game'] . '&user=' . $team3['ID'] . '">' . $team3['player'] . "</a><br>"; ?> </td> </table> <?php } }?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/52512-solved-parse-error-parse-error-unexpected-t_string/#findComment-259230 Share on other sites More sharing options...
aaronk7 Posted May 22, 2007 Author Share Posted May 22, 2007 Thank You. Quote Link to comment https://forums.phpfreaks.com/topic/52512-solved-parse-error-parse-error-unexpected-t_string/#findComment-259323 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.