[RESOLVED] Unexpected T String error
Results 1 to 10 of 10

Thread: [RESOLVED] Unexpected T String error

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Location
    Australia
    Posts
    7

    resolved [RESOLVED] Unexpected T String error

    Hi,
    I'm new to coding and downloaded an old game script to try to teach myself and have been watching and taking lessons from codeschool, I can not with my knowledge work out what is wrong with this line:
    PHP Code:
        echo '« <a href="http://'.$_SERVER['PHP_SELF'].'?act=add" target="_blank">Add Game</a> » 
    I recieve this error message: Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/****/public_html/5050.php on line 86.

    Here is the full code, could you please not just tell me what to do but EXPLAIN it so I learn from my mistakes Thanks so much!

    PHP Code:
    <?php
    require_once("globals.php");

    class 
    chance extends headers {

    public 
    $error = array();
    public 
    $minbet 1;
    public 
    $maxbet 1000;
    public 
    $maxgames 10;

    public function 
    _back()
        {
            echo 
    '<a href="http://javascript<b></b>: history.go(-1)" target="_blank">Back</a>';
        }
    public function 
    _errors($error)
        {
            if (!empty(
    $error))
            {
                echo
    'The following errors occured';
                foreach (
    $error as $er)
                {
                    echo 
    ''$er;
                }
                unset(
    $error);
                
    $this->_back();
                
    $this->endpage();
                exit;
            }
        }
    public function 
    _fetchUser($col)
        {
            
    $SQL sprintf("SELECT `"$col ."` FROM `users` WHERE `userid` = %u"$_SESSION['userid']);
            
    $exe mysql_query($SQL);
            
    $fetch mysql_fetch_array($exe);
            return 
    $fetch[$col];
        }
    public function 
    _add()
        {
            if(isset(
    $_POST['submit']))
            {
                if (
    preg_match("/[^0-9]/i"$_POST['amt'])) 
                    { 
                        
    $this->error[] = 'Amount must be numeric'
                    }
                if(
    $_POST['amt'] < $this->minbet
                { 
                    
    $this->error[] = 'The minimum bet is '$this->minbet
                }
                
    $SQL sprintf("SELECT COUNT(`logID`) amount FROM `chance` WHERE `userID` = %u AND `active` = 1"$this->_fetchUser('userid'));
                
    $exe mysql_query($SQL);
                
    $check mysql_fetch_array($exe);
                if(
    $check['amount'] >= $this->maxgames
                { 
                    
    $this->error[] = 'There is a maximum of '$this->maxgames
                }
                if(
    $_POST['amt'] > $this->_fetchUser('money')) 
                { 
                    
    $this->error[] = 'You cannot afford that amount.'
                }
                
    $this->_errors($this->error);
                
    $SQL_2 sprintf("UPDATE `users` SET `money` = `money` - %u WHERE `userid` = %u",
                
    $_POST['amt'],
                
    $this->_fetchUser('userid'));
                
    mysql_query($SQL_2);
                
    $SQL_3 sprintf("INSERT INTO `chance` (`logID`, `userID`, `amount`, `active`)
                VALUES (NULL, %u, %u, 1)"
    $this->_fetchUser('userid'), $_POST['amt']);
                
    mysql_query($SQL_3);
                echo 
    'Your game has been set. Good Luck.';

            }
            else
            {
                echo 
    'Adding a game
                <form action="'
    .$_SERVER['PHP_SELF'].'?act=add" method="POST">
                Cash: <input type="text" name="amt" size="10" maxlength="10" />
                <input type="submit" name="submit" value="Add!"></form>

                « '
    $this->maxgames .' games max per user »';
            }
        }
    public function 
    _view_games()
        {

            
    $SQL "SELECT t.* , u.username FROM `chance` t LEFT JOIN `users` u on u.userid = t.userID WHERE t.active = 1 ORDER BY t.logID ASC";
            
    $exe mysql_query($SQL);
            echo 
    '« <a href="http://'.$_SERVER['PHP_SELF'].'?act=add" target="_blank">Add Game</a> »
            Table of users awaiting a challenge
            <table width="
    75%">
            <tr>
            <td><u>Game ID</u></td>
            <td><u>User</u></td>
            <td><u>Amount</u></td>
            <td><u>Challenge</u></td>
            <td><u>Cancel</u></td>
            </tr>';
            while(
    $r = mysql_fetch_array($exe)) {
            echo '<tr>
            <td>'. 
    $r['logID'] .'</td>
            <td><a href="
    http://viewuser.php?u='. $r['userID'] .'" target="_blank">'. $r['username'] .'</a> ['. $r['userID'] .']</td>
            
    <td>'. $r['amount'] .'</td>
            <
    td><a href="http://'. $_SERVER['PHP_SELF'] .'?act=challenge&ID='. urlencode($r['logID']) .'" target="_blank">Challenge</a></td>
            <
    td>';
            if($this->_fetchUser('
    userid') == $r['userID']){ echo '<a href="http://'. $_SERVER['PHP_SELF'] .'?act=cancel&ID='. urlencode($r['logID']) .'" target="_blank">Cancel</a>'; }************ 
            echo '
    </td>
            </
    tr>';
            }
            echo '
    </table>';
            }
    public function _challenge() {
    *****
    ****$SQL = sprintf("SELECT t.*, u.username FROM `chance` t LEFT JOIN `users` u ON t.userID = u.userid WHERE t.logID = %u AND t.active = 1 LIMIT 1", $_GET['
    ID']);
    ****$exe = mysql_query($SQL);
    ****$fetch = mysql_fetch_array($exe);
    *****
    ****if(!empty($fetch['
    logID'])) {
    *
    ********if($fetch['
    amount'] > $this->_fetchUser('money')){ $this->error[] = 'You cannot afford the challenge amount.'; }
    ********if($this->_fetchUser('
    userid') == $r['userID']){ $this->error[] = 'You cannot accept your own challenge.'; }
    ********$this->_errors($this->error);
    *********
    ********if(mt_rand(1,2) == 1) {
    ************$winner = $fetch['
    userID']; 
    ************$loser = $this->_fetchUser('
    userid');
    ************$winnername = $fetch['
    username'];
    ************$losername = $this->_fetchUser('
    username');
    ************$string = '
    <font color="red">Sorryyou LostBetter luck next time.</font>';
    ************$SQL_2 = sprintf("UPDATE `users` SET `money` = `money` - %u WHERE `userid` = %u", $fetch['
    amount'], $this->_fetchUser('userid'));
    ************$SQL_3 = sprintf("UPDATE `users` SET `money` = `money` + (%u * 2) WHERE `userid` = %u", $fetch['
    amount'], $fetch['userID']);
    ************mysql_query($SQL_2);
    ************mysql_query($SQL_3);
    ********}
    ********else {
    ************$winner = $this->_fetchUser('
    userid'); 
    ************$loser = $fetch['
    userID'];
    ************$winnername = $this->_fetchUser('
    username');
    ************$losername = $fetch['
    username'];
    ************$string = '
    You WonCongratulations!
    <
    font color="green"You Won '. money_formatter($fetch['amount']) .'!</font>';
    ************$SQL_4 = sprintf("UPDATE `users` SET `money` = `money` + %u WHERE `userid` = %u", $fetch['
    amount'], $this->_fetchUser('userid'));
    ************mysql_query($SQL_4);
    ********}
    ********event_add($winner, '
    The game of '. money_formatter($fetch['amount']) .' challenged by <a href="http://viewuser.php?u= '. urlencode($this->_fetchUser('userid')) .'" target="_blank">'. $this->_fetchUser('username') .'</a
    ********
    was won by <a href="http://viewuser.php?u='. urlencode($winner) .'" target="_blank">'. $winnername .'</a>.', $t);
    ********event_add($loser, '
    The game of '. money_formatter($fetch['amount']) .'challenged by <a href="http://viewuser.php?u='. urlencode($this->_fetchUser('userid')) .'" target="_blank">'. $this->_fetchUser('username') .'</a
    ********
    was won by <a href="http://viewuser.php?u='. urlencode($winner) .'" target="_blank">'. $winnername .'</a>.', $t);
    ********$SQL_5 = sprintf("UPDATE `chance` SET `active` = 0 WHERE `logID` = %u", $_GET['
    ID']);
    ********mysql_query($SQL_5);
    ********echo $string;
    ****}
    ****else{ echo '
    This game has either been cancelled or someone played before you got the 5050.'; }
    }
    *
    public function _cancel() {
    *
    ****$SQL = sprintf("SELECT `amount` from `chance` where `logID` = %u AND `active` = 1", $_GET['
    ID']);
    ****$exe = mysql_query($SQL);
    ****$fetch = mysql_fetch_array($exe);
    *****
    ****if(!empty($fetch['
    amount']))
    ****{
    ********$SQL_2 = sprintf("UPDATE `users` SET `money` = `money` + %u WHERE `userid` = %u", $fetch['
    amount'], $this->_fetchUser('userid'));
    ********$SQL_3 = sprintf("UPDATE `chance` SET `active` = -1 WHERE `logID` = %u", $_GET['
    ID']);
    ********mysql_query($SQL_2);
    ********mysql_query($SQL_3);
    ********echo '
    The game has been cancelled, and your money has been returned.';
    ****}
    ****else { echo '
    This game has already been canceleddoes not exist, or someone already played.'; }
    *
    }
    }
    *
    $cha = new chance();
    *
    echo '
    <h1>50 50 money Game</h1>';
    *
    switch($_GET['
    act']) {
    ****case '
    cancel': $cha->_cancel(); break;
    ****case '
    challenge': $cha->_challenge(); break;
    ****case '
    add': $cha->_add(); break;
    ****default: $cha->_view_games(); break;
    }
    *
    ?>

  2. #2
    Junior Member
    Join Date
    Dec 2012
    Location
    Australia
    Posts
    7
    I am also having another T-String error where it does not define what is wrong just the line. this page reads

    http://codepad.org/VUrwBmWC

    It refers me to this line
    PHP Code:
    $query3=sprintf("SELECT `uid` FROM `session_chat` WHERE `uid`='%d'"$ir['userid']); 
    This may sound stupid but does anyone have a resource link handy that will explain what these error codes mean? Sorry for taking up so much time, thanks
    JKH

  3. #3
    Pedantic Curmudgeon Weedpacket's Avatar
    Join Date
    Aug 2002
    Location
    General Systems Vehicle "Thrilled To Be Here"
    Posts
    21,889
    What are you using for an editor? I ask because the syntax highlighting breaks for no apparent reason in your _view_games() function. And if I copy it and check for syntax errors myself I don't find any except for those due to the spurious *s that start at line 103 (the body of the _challenge() function), which also suggest that your editor is mangling your code.

    (FWIW, T_STRING is a pretty generic token; see tokens.)
    Last edited by Weedpacket; 12-30-2012 at 04:18 AM.
    THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER
    FAQs! FAQs! FAQs! Most forums have them!
    Search - Debugging 101 - Collected Solutions - General Guidelines - Getting help at all

  4. #4
    Junior Member
    Join Date
    Dec 2012
    Location
    Australia
    Posts
    7
    Thanks for the prompt reply I am using notepad++ as my editor. The first time I saw the *s was upon copying it here.

  5. #5
    Junior Member
    Join Date
    Dec 2012
    Location
    Australia
    Posts
    7
    Also thanks for the link on tokens I'll read up on it tonight

  6. #6
    Junior Member
    Join Date
    Dec 2012
    Location
    Australia
    Posts
    7
    I went ahead and removed what looked like blank spaces, but was *** when view in hexidecimal view, but i still recieve the same error, any suggestion on what I can do to remove the error? Thanks

  7. #7
    Junior Member
    Join Date
    Dec 2012
    Location
    Australia
    Posts
    7

    UPDATE REPLY

    I found what was causing the error, now the only error I am receiving is "PHP Syntax Check: Parse error: syntax error, unexpected T_ECHO in your code on line 112"
    PHP Code:
    echo '</td></tr>'
    Whole code now:
    PHP Code:
    <?php
    require_once("globals.php");

    class 
    chance extends headers 
    {
    public 
    $error = array();
    public 
    $minbet 1;
    public 
    $maxbet 1000;
    public 
    $maxgames 10;

    public function 
    _back()
        {
            echo 
    '<a href="http://javascript<b></b>: history.go(-1)" target="_blank">Back</a>';
        }
    public function 
    _errors($error)
        {
            if (!empty(
    $error))
            {
                echo
    'The following errors occured';
                foreach (
    $error as $er)
                {
                    echo 
    ''$er;
                }
                unset(
    $error);
                
    $this->_back();
                
    $this->endpage();
                exit;
            }
        }
    public function 
    _fetchUser($col)
        {
            
    $SQL sprintf("SELECT `"$col ."` FROM `users` WHERE `userid` = %u"$_SESSION['userid']);
            
    $exe mysql_query($SQL);
            
    $fetch mysql_fetch_array($exe);
            return 
    $fetch[$col];
        }
    public function 
    _add()
        {
            if(isset(
    $_POST['submit']))
            {
                if (
    preg_match("/[^0-9]/i"$_POST['amt'])) 
                    { 
                        
    $this->error[] = 'Amount must be numeric'
                    }
                if(
    $_POST['amt'] < $this->minbet
                { 
                    
    $this->error[] = 'The minimum bet is '$this->minbet
                }
                
    $SQL sprintf("SELECT COUNT(`logID`) amount FROM `chance` WHERE `userID` = %u AND `active` = 1"$this->_fetchUser('userid'));
                
    $exe mysql_query($SQL);
                
    $check mysql_fetch_array($exe);
                if(
    $check['amount'] >= $this->maxgames
                { 
                    
    $this->error[] = 'There is a maximum of '$this->maxgames
                }
                if(
    $_POST['amt'] > $this->_fetchUser('money')) 
                { 
                    
    $this->error[] = 'You cannot afford that amount.'
                }
                
    $this->_errors($this->error);
                
    $SQL_2 sprintf("UPDATE `users` SET `money` = `money` - %u WHERE `userid` = %u",
                
    $_POST['amt'],
                
    $this->_fetchUser('userid'));
                
    mysql_query($SQL_2);
                
    $SQL_3 sprintf("INSERT INTO `chance` (`logID`, `userID`, `amount`, `active`)
                VALUES (NULL, %u, %u, 1)"
    $this->_fetchUser('userid'), $_POST['amt']);
                
    mysql_query($SQL_3);
                echo 
    'Your game has been set. Good Luck.';

            }
            else
            {
                echo 
    'Adding a game
                <form action="'
    .$_SERVER['PHP_SELF'].'?act=add" method="POST">
                Cash: <input type="text" name="amt" size="10" maxlength="10" />
                <input type="submit" name="submit" value="Add!"></form>

                « '
    $this->maxgames .' games max per user »';
            }
        }
    public function 
    _view_games()
        {

            
    $SQL "SELECT t.* , u.username FROM `chance` t LEFT JOIN `users` u on u.userid = t.userID WHERE t.active = 1 ORDER BY t.logID ASC";
            
    $exe mysql_query($SQL);
            echo 
    '
                    « <a href="'
    .$_SERVER['PHP_SELF'].'?act=add">Add Game</a> »
                    Table of users awaiting a challenge
                    <table width="75%">
                    <tr>
                    <td><u>Game ID</u></td>
                    <td><u>User</u></td>
                    <td><u>Amount</u></td>
                    <td><u>Challenge</u></td>
                    <td><u>Cancel</u></td>
                    </tr>
                '
    ;
            while(
    $r mysql_fetch_array($exe)) 
                {
                    echo 
    '
                            <tr>
                            <td>'
    $r['logID'] .'</td>
                            <td><a href="viewuser.php?u=&'
    $r['userID'] .'">'$r['username'] .'</a> ['$r['userID'] .']</td>
                            <td>'
    $r['amount'] .'</td>
                            <td><a href="'
    $_SERVER['PHP_SELF'] .'?act=challenge&ID='urlencode($r['logID']) .'">Challenge</a></td>
                            <td>
                        '
    ;
                    if(
    $this->_fetchUser('userid') == $r['userID'])
                        {
                        echo 
    '<a href="'$_SERVER['PHP_SELF'] .'?act=cancel&ID='urlencode($r['logID']) .'">Cancel</a>'
                        }************ 
                    echo 
    '</td>
                    </tr>'
    ;
                }
            echo 
    '</table>';
            }
    public function 
    _challenge() 
    {
        
    $SQL sprintf("SELECT t.*, u.username FROM `chance` t LEFT JOIN `users` u ON t.userID = u.userid WHERE t.logID = %u AND t.active = 1 LIMIT 1"$_GET['ID']);
        
    $exe mysql_query($SQL);
        
    $fetch mysql_fetch_array($exe);
        if(!empty(
    $fetch['logID'])) 
            {
                if(
    $fetch['amount'] > $this->_fetchUser('money'))
                    {
                        
    $this->error[] = 'You cannot afford the challenge amount.'
                    }
                if(
    $this->_fetchUser('userid') == $r['userID'])
                    { 
                        
    $this->error[] = 'You cannot accept your own challenge.'
                    }
                
    $this->_errors($this->error);
                if(
    mt_rand(1,2) == 1
                    {
                        
    $winner $fetch['userID']; 
                        
    $loser $this->_fetchUser('userid');
                        
    $winnername $fetch['username'];
                        
    $losername $this->_fetchUser('username');
                        
    $string '<font color="red">Sorry, you Lost. Better luck next time.</font>';
                        
    $SQL_2 sprintf("UPDATE `users` SET `money` = `money` - %u WHERE `userid` = %u"$fetch['amount'], $this->_fetchUser('userid'));
                        
    $SQL_3 sprintf("UPDATE `users` SET `money` = `money` + (%u * 2) WHERE `userid` = %u"$fetch['amount'], $fetch['userID']);
                        
    mysql_query($SQL_2);
                        
    mysql_query($SQL_3);
                    }
                else 
                    {
                        
    $winner $this->_fetchUser('userid'); 
                        
    $loser $fetch['userID'];
                        
    $winnername $this->_fetchUser('username');
                        
    $losername $fetch['username'];
                        
    $string 'You Won! Congratulations!
                        <font color="green"> You Won '
    money_formatter($fetch['amount']) .'!</font>';
                        
    $SQL_4 sprintf("UPDATE `users` SET `money` = `money` + %u WHERE `userid` = %u"$fetch['amount'], $this->_fetchUser('userid'));
                        
    mysql_query($SQL_4);
                    }
                
    event_add($winner'The game of 'money_formatter($fetch['amount']) .' challenged by <a href="viewuser.php?u= 'urlencode($this->_fetchUser('userid')) .'">'$this->_fetchUser('username') .'</a> 
                was won by <a href="viewuser.php?u='
    urlencode($winner) .'">'$winnername .'</a>.'$t);
                
    event_add($loser'The game of 'money_formatter($fetch['amount']) .'* challenged by <a href="viewuser.php?u='urlencode($this->_fetchUser('userid')) .'">'$this->_fetchUser('username') .'</a> 
                was won by <a href="viewuser.php?u='
    urlencode($winner) .'">'$winnername .'</a>.'$t);
                
    $SQL_5 sprintf("UPDATE `chance` SET `active` = 0 WHERE `logID` = %u"$_GET['ID']);
                
    mysql_query($SQL_5);
                echo 
    $string;
            }
        else
            {
                echo 
    'This game has either been cancelled or someone played before you got the 5050.'
            }
    }
    public function 
    _cancel() 
        {
            
    $SQL sprintf("SELECT `amount` from `chance` where `logID` = %u AND `active` = 1"$_GET['ID']);
            
    $exe mysql_query($SQL);
            
    $fetch mysql_fetch_array($exe);
            if(!empty(
    $fetch['amount']))
                {
                    
    $SQL_2 sprintf("UPDATE `users` SET `money` = `money` + %u WHERE `userid` = %u"$fetch['amount'], $this->_fetchUser('userid'));
                    
    $SQL_3 sprintf("UPDATE `chance` SET `active` = -1 WHERE `logID` = %u"$_GET['ID']);
                    
    mysql_query($SQL_2);
                    
    mysql_query($SQL_3);
                    echo 
    'The game has been cancelled, and your money has been returned.';
                }
            else 
                {
                    echo 
    'This game has already been canceled, does not exist, or someone already played.';
                }
    *
        }
    }
    $cha = new chance();
    echo 
    '<h1>50 / 50 money Game</h1>';
    switch(
    $_GET['act']) 
        {
            case 
    'cancel'$cha->_cancel(); break;
            case 
    'challenge'$cha->_challenge(); break;
            case 
    'add'$cha->_add(); break;
            default: 
    $cha->_view_games(); break;
        }
    ?>
    Thanks for the help.

  8. #8
    High Energy Magic Dept. NogDog's Avatar
    Join Date
    Aug 2006
    Location
    Ankh-Morpork
    Posts
    13,949
    Looks like those dreaded asterisks again:
    PHP Code:
                        }************ 
                    echo 
    '</td>
                    </tr>'

    Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be." ~ from Nation, by Terry Pratchett

    "But the main reason that any programmer learning any new language thinks the new language is SO much better than the old one is because he’s a better programmer now!" ~ http://www.oreillynet.com/ruby/blog/...ck_to_p_1.html


    eBookworm.us

  9. #9
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,429
    The asterisks usually indicate some extended ASCII or odd Unicode character that the vBulletin software didn't like.

    For example, between the following quotes, I'll place four non-breaking spaces (U+00A0, "&nbsp;" as an HTML entity, Alt+0160 on the number pad): "****".

  10. #10
    Junior Member
    Join Date
    Dec 2012
    Location
    Australia
    Posts
    7
    Thank you NogDog for showing me my error Thank you brad for explaining it I hope you both have a prosperous new year

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •