Jump to content

Archived

This topic is now archived and is closed to further replies.

jeffshen

Parse error: parse error, unexpected T_VARIABLE

Recommended Posts

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?

[code]
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
    ?>
[/code]


Thanks,

Jeff

Share this post


Link to post
Share on other sites
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.....

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
[code]15  //Connect to MySQL Database
    include("login.php");
    mysql_connect("localhost",$username,$password);
    @mysql_select_db($database) or die("Unable to select database");[/code]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Can you post the script after the first fixes?

Orio.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

×

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.