0

I have installed Xampp on my laptop recently and am trying to display the following query:

display.php

<?php
    // Send variables for the MySQL database class.
    $database = mysqli_connect('localhost', 'root', '','game_db') or die('Could not connect: ' . mysql_error());
   // mysql_select_db('my_database') or die('Could not select database');
 
    $query = "SELECT * FROM `scores` ORDER by `score` DESC LIMIT 5";
    $result = mysqli_query($database,$query) or die('Query failed: ' . mysql_error());
 
    $num_results = mysql_num_rows($result);  
 
    for($i = 0; $i < $num_results; $i++)
    {
         $row = mysql_fetch_array($result);
         echo $row['name'] . "\t" . $row['score'] . "\n";
    }
?>

I have this xampp installed in my 'A' Drive and this file is saved in htdocs folder of xampp but whenever i run it as localhost/display.php in any browser it gives me this error:

 Parse error: syntax error, unexpected '$query' (T_VARIABLE) in 
    A:\xampp\htdocs\display.php on line 6

I have done the same things on various laptops on my friends they work with the same code but not on mine, why?

James Z
  • 12,209
  • 10
  • 24
  • 44
  • `mysql_num_rows` ... `mysql_fetch_array` ... oops! You should be using the `mysqli_` variants ;) Note the 'i'. – IncredibleHat Jan 15 '18 at 16:18
  • Probably invisible characters. And the same code won't work for your friends as you're also mixing mysql and mysqli which just won't work. – John Conde Jan 15 '18 at 16:22
  • I see no syntax error either in whats pasted above. That code parses for me... and promptly errors on the connection as expected. – IncredibleHat Jan 15 '18 at 16:23
  • You might not remember the time of floppy disks, but I wouldn't recommend using A or B drives for hard drives. – James Z Jan 15 '18 at 16:32

0 Answers0