I am getting the following error when trying to pull data from a MySQL database:
Warning: mysql_query() expects parameter 1 to be string, resource given
I have tried many changes to remedy the problem but I am really just guessing at what the problem is.
Here is my code:
// Create connection
$conn = mysql_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysql_connect_error());
}
$sql = "SELECT * FROM doginfo WHERE breed='$dog'";
$result = mysql_query($conn, $sql);
if (mysql_num_rows($result) > 0) {
// output data of each row
while($row = mysql_fetch_assoc($result)) {
echo nl2br("Breed: " . $row["breed"] . "\n" . "Size: " . $row["size"] . "\n" . "Height: " . $row["height"] . "\n" "Weight: " . "\n" . $row["weight"] . "\n" . "Life Expectancy: " . $row["life"] . "\n");
}
} else {
echo "No results found!";
}
mysql_close($conn);