boynedmaster Posted March 4, 2013 Share Posted March 4, 2013 (edited) 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 March 4, 2013 by boynedmaster Quote Link to comment https://forums.phpfreaks.com/topic/275200-syntax-error-unexpected/ Share on other sites More sharing options...
haku Posted March 4, 2013 Share Posted March 4, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/275200-syntax-error-unexpected/#findComment-1416368 Share on other sites More sharing options...
boynedmaster Posted March 4, 2013 Author Share Posted March 4, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/275200-syntax-error-unexpected/#findComment-1416369 Share on other sites More sharing options...
Solution teynon Posted March 4, 2013 Solution Share Posted March 4, 2013 (edited) 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 March 4, 2013 by teynon Quote Link to comment https://forums.phpfreaks.com/topic/275200-syntax-error-unexpected/#findComment-1416370 Share on other sites More sharing options...
haku Posted March 4, 2013 Share Posted March 4, 2013 And when I jump from 20 feet into water, I'm fine, while if I jump from 20 feet onto concrete, I die. Quote Link to comment https://forums.phpfreaks.com/topic/275200-syntax-error-unexpected/#findComment-1416371 Share on other sites More sharing options...
teynon Posted March 4, 2013 Share Posted March 4, 2013 And when I jump from 20 feet into water, I'm fine, while if I jump from 20 feet onto concrete, I die. You die from 20 feet? I could see getting hurt, perhaps. Quote Link to comment https://forums.phpfreaks.com/topic/275200-syntax-error-unexpected/#findComment-1416372 Share on other sites More sharing options...
haku Posted March 4, 2013 Share Posted March 4, 2013 (edited) Sorry, I'm not American, I don't understand feet so well. It was an analogy. Edited March 4, 2013 by haku Quote Link to comment https://forums.phpfreaks.com/topic/275200-syntax-error-unexpected/#findComment-1416373 Share on other sites More sharing options...
teynon Posted March 4, 2013 Share Posted March 4, 2013 I know, i'm just kidding. 20 feet is like 4 people tall Quote Link to comment https://forums.phpfreaks.com/topic/275200-syntax-error-unexpected/#findComment-1416374 Share on other sites More sharing options...
boynedmaster Posted March 4, 2013 Author Share Posted March 4, 2013 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!!!!!!! Quote Link to comment https://forums.phpfreaks.com/topic/275200-syntax-error-unexpected/#findComment-1416375 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.