I am trying to select data from my database - here's the script:
<?php
$connect = mysql_connect("database", "username", "password")
or die("Error: Could not connect to the database. Please try again later.");
print "Connected successfully";
$db = mysql_select_db("stockists",$connect)
or die ("Couldn't select database");
$query = "SELECT * from stockists WHERE stockists2.postcode like 'tn%'";
$result = mysql_query($query,$connect);
$num_results = mysql_num_rows($result);
echo "<p>Number of stockists found: ".$num_results."</p>";
?>
It connects successfully but I get the error message:
"Supplied argument is not a valid MySQL result resource " relating to the "$num_results = mysql_num_rows($result);" line.
When I run the Mysql_error() it tells me my database is not selected. Can anyone help please?
Thanks