Jump to content

Syntax error, unexpected '['


Go to solution Solved by teynon,

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>";
    }
?>
Edited by boynedmaster
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.

  • Solution

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

Edited by teynon

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!!!!!!!

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.