I am very new to PHP, trying to write a script which connects to a MySQL database and simply displays the contents in list format under each heading;
My table contains an ID (AutoIncrement), FName, SName & EAddress fields.
The database is called iphonehe_MGFSales and the username is iphonehe_MGFSale - I have added the user to the DB with full privileges.
I am trying to establish my connection to the DB using the mysql function with this code;
mysql_connect ("localhost", "iphonehe_MGFSale", "xxxxxxx") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("iphonehe_MGFSales");
The table I have created is called MGFSales DB. I am using this code to attempt to build the query;
$query = mysql_query("SELECT * FROM MGFSales_DB");
And finally I am trying to display the results using the following code;
while ($row = mysql_fetch_array ($query)) {
echo "<br /> ID: " .$row['ID']. "<br /> First Name: ".$row['FName']. "<br /> Last Name: ".$row['LName']. "<br /> Email: ".$row['EAddress']. "<br />";
}
I have named the file index.php and uploaded to my server, when running I get the following error 'Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/iphonehe/public_html/pauldmorris.co.uk/mgf/index.php on line 16'
Anyone point me in the right direction? Line 16 of my code seems pretty tight from what I can see, am i overlooking something? Thanks