Jump to content

Syntax error, unexpected '['


boynedmaster

Recommended Posts

I'm making a php site, and mysql_fetch_array does this:

Syntax error, unexpected '['

 

Full error: Parse error: syntax error, unexpected '[' in /www/zzl.org/r/o/b/robloxoctopus/htdocs/inc/inc.php on line 17

 

 

Line 17:

 

 
<?php
    //Connect to MySQL
    function connect()
    {
        mysql_connect("localhost", "*******", "**********");
        mysql_select_db("robloxoctopus_zzl_db");
    }
    
    //Find the most recent review and display it
    function newRecentReview()
    {
        connect();
        $tq = mysql_query("SELECT `game` FROM reviews ORDER BY `date` DESC LIMIT 1");
        $rq = mysql_query("SELECT `review` FROM reviews ORDER BY `date` DESC LIMIT 1");
        $picq = mysql_query("SELECT `thumbnail` FROM reviews ORDER BY `date` DESC LIMIT 1");
        $sq = mysql_query("SELECT `short` FROM reviews ORDER BY `date` DESC LIMIT 1");
        $title = mysql_fetch_array($tq)[0];
        $ltitle = str_replace(' ', '-', strtolower($title));
        $review = mysql_fetch_array($sq)[0];
        $thumbnail = mysql_fetch_array($picq)[0];
        echo "<center> <b style='font-size:large'> $title </b> </center>'";
        echo "<center> <a href='reviews/$ltitle.php'><img src='$thumbnail' alt='$title'/></a></center>";
        echo "<center> <p style='font-size:small'> \"$review\"... </p> </center>";
    }
?>
Link to comment
https://forums.phpfreaks.com/topic/275200-syntax-error-unexpected/
Share on other sites

It's telling you the exact line where the error is happening, and the character at which the error is happening:

 

Line 17:

$title = mysql_fetch_array($tq)[0];
Unexpected character:

[

 

Look at the [ character in that line. It's not supposed to be there. Or in other words, this line of code is written incorrectly.

 

It's telling you the exact line where the error is happening, and the character at which the error is happening:

 

Line 17:

$title = mysql_fetch_array($tq)[0];
Unexpected character:

[

 

Look at the [ character in that line. It's not supposed to be there. Or in other words, this line of code is written incorrectly.

I know I saw, but when I did it in localhost, it worked.

PHP 5.4 supports what you are trying to do. PHP 5.3 and prior do not support using a function's return value like that. Your server is probably on a different PHP version than your localhost.

http://php.net/manual/en/language.types.array.php#example-88

Thank you!!!!!!!

Archived

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

×
×
  • 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.