Jump to content

Recommended Posts

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.

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?

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!

ok i will post the code of all the stuff i have in my file.

I will trust you guys :P

 

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>
");
}
}
}
?>

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

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.

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.