Jump to content


Photo

Parse error: parse error, unexpected T_VARIABLE


  • This topic is locked This topic is locked
6 replies to this topic

#1 jeffshen

jeffshen
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 08 August 2006 - 11:35 AM

Hey all,

I've written this piece of code and an error is coming up as:

Parse error: parse error, unexpected T_VARIABLE in /var/www/html/stocks/test.php on line 21

I've tried googling the topic and see that its something to do with missing punctuation... but I cant find the mistake... can someone please help?

1   <table border="1" cellspacing="2" cellpadding="2">
    <tr> 
    <th><font face="Arial, Helvetica, sans-serif">Symbol</font></th>
    <th><font face="Arial, Helvetica, sans-serif">Name</font></th>
5   <th><font face="Arial, Helvetica, sans-serif">Time</font></th>
    <th><font face="Arial, Helvetica, sans-serif">Date</font></th>
    <th><font face="Arial, Helvetica, sans-serif">Last</font></th>
    <th><font face="Arial, Helvetica, sans-serif">Change</font></th>
    <th><font face="Arial, Helvetica, sans-serif">High</font></th>
10 <th><font face="Arial, Helvetica, sans-serif">Low</font></th>
    </tr>
    
    <?php
    
15  //Connect to MySQL Database
    include("login.php");
    mysql_connect("localhost",$username,$password);
    @mysql_select_db($database or die("Unable to select database")
    
20  //Select All Records from Stocks Database
    $query = "SELECT * FROM stocks";
    $result = mysql_query($query);
    
    //returns the row of the MySQL Query
25  $row = mysql_num_rows($result);
    $i = 0
    
    //Selects the Stock Code of the Stock
    $asking = mysql_result($result,$i,"code")
30  
    //add .hk to the end of the stocknumber, required for Yahoo! Finance
    $standard = ".hk";

    //Put the two together to allow one stock number with .hk at the end for YahoO!
35  $findquote = "$asking$standard";
    
    //Connects to Yahoo! and retrives the records from Yahoo!'s database
    Class yahoo
    {
40  function get_stock_quote($symbol) 
    {
    $url = sprintf("http://finance.yahoo.com/d/quotes.csv?s=%s&f=snl1d1t1c1ohgv" ,$symbol); 
    $fp = fopen($url, "r");
    if(!fp)
45  {
    echo "error : cannot recieve stock quote information";
    }
    else
    {
50  $array = fgetcsv($fp , 4096 , ', ');
    fclose($fp);
    $this->symbol = $array[0];
    $this->name = $array[1];
    $this->last = $array[2];
55  $this->date = $array[3];
    $this->time = $array[4];
    $this->change = $array[5];
    $this->open = $array[6];
    $this->high = $array[7];
60  $this->low = $array[8];
    $this->volume = $array[9];
    }
    }
    }
65    
    //loop the function for multiple database entries
    while ($i < $row) {
    
    //Executes the script for the records retrival
70  $quote = new yahoo;
    $quote->get_stock_quote("$findquote");
    ?>

    //Print the information into a tabular format
75  <tr> 
    <td><font face="Arial, Helvetica, sans-serif"><? echo "$quote->symbol"; ?></font></td>
    <td><font face="Arial, Helvetica, sans-serif"><? echo "$quote->name"; ?></font></td>
    <td><font face="Arial, Helvetica, sans-serif"><? echo "$quote->time"; ?></font></td>
    <td><font face="Arial, Helvetica, sans-serif"><? echo "$quote->date"; ?></font></td>
80  <td><font face="Arial, Helvetica, sans-serif"><? echo "$quote->last"; ?></font></td>
    <td><font face="Arial, Helvetica, sans-serif"><? echo "$quote->change"; ?></font></td>
    <td><font face="Arial, Helvetica, sans-serif"><? echo "$quote->high"; ?></font></td>
    <td><font face="Arial, Helvetica, sans-serif"><? echo "$quote->low"; ?></font></td>

85
    </tr>
    </table>

    <?
90  ++$i
    ?>


Thanks,

Jeff

#2 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 08 August 2006 - 11:42 AM

only probelsm i can see there are missing ';'

    //returns the row of the MySQL Query
25  $row = mysql_num_rows($result);
    $i = 0; //HERE
   
    //Selects the Stock Code of the Stock
    $asking = mysql_result($result,$i,"code"); // HERE
30 



    <?
90  ++$i; // HERE
    ?>

ALSO Good practice NOT to use short tags (<?) for php use <?php instead.....

follow me on twitter @PHPsycho

#3 jeffshen

jeffshen
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 08 August 2006 - 11:47 AM

Thank you for pointing out my silly mistakes, however the problem on line 21 still exists... Can anyone spot the error please?

Thanks a lot,

Jeff

#4 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 08 August 2006 - 12:03 PM

15  //Connect to MySQL Database
    include("login.php");
    mysql_connect("localhost",$username,$password);
    @mysql_select_db($database) or die("Unable to select database");


#5 jeffshen

jeffshen
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 08 August 2006 - 12:46 PM

Hey

Thanks for yet spotting another silly mistake... however it still states that


Parse error: parse error, unexpected T_VARIABLE in /var/www/html/stocks/test.php on line 21


Thanks,

Jeff

#6 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 08 August 2006 - 12:52 PM

Can you post the script after the first fixes?

Orio.
Think you're smarty?

(Gone until 20 to November)

#7 jeffshen

jeffshen
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 08 August 2006 - 01:56 PM

Hey all,

I found the mistake at like 18, I forgot the ) and ;

15  //Connect to MySQL Database
    include("login.php");
    mysql_connect("localhost",$username,$password);
    @mysql_select_db($database) or die("Unable to select database"); <-- ) after $datavase and ; wasnt in the original script

Thanks a lot for everybody's prompt reply,

Jeff




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users