-4

I am trying to connect to MySQL DB and display data in an array. I have AMPPS installed and the DB is loaded into phpMyAdmin. When I try to open this PHP code the web page appears blank and gives me a 404 error.

<?php
mysql_connect("localhost","root","")or die("could not connect to mysql");
mysql_select_db("maps")or die("could not find db check spelling kimo sabi");
error_reporting(5);
$resource = mysql_query("SELECT * FROM 'locations'");
while($row=  mysql_fetch_assoc($resource))
{$data[] = $row;}
print($data); die();
?>

I am using Netbeans IDE. I have tried both to run the file and to manually open it. The name of the file is default NewemptyPHP

Francisco
  • 10,918
  • 6
  • 34
  • 45
user3856234
  • 63
  • 1
  • 10
  • 2
    If you're getting a 404, the problem does not lie with php. Double check that the file is where you think it is. – castis Sep 26 '14 at 19:42
  • Thank you for the reply. However I have created several new files in the same project and they all open without a problem. I can also higlight the file and click run file as and it still will not open – user3856234 Sep 26 '14 at 19:49
  • There should not be any space in file name try something else as file.php etc – Imran Tufail Sep 26 '14 at 19:50
  • Make sure apache or nginx or whatever is allowed to at least read the file. – castis Sep 26 '14 at 19:51
  • 2
    Aside from the question: Don't use mysql_ as it's deprecated. Use mysqli or PDO instead. – icecub Sep 26 '14 at 20:00

1 Answers1

0

You're using the wrong identifiers for your table, which are quotes.

("SELECT * FROM 'locations'")
                ^         ^

Either remove them:

("SELECT * FROM locations")

or wrap the table name in backticks:

("SELECT * FROM `locations`")

Use mysql_error() to identify errors.


Sidenote:

Your present code is open to SQL injection.
Use mysqli_ with prepared statements, or PDO with prepared statements, they're safer.

Community
  • 1
  • 1
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141