Hi all,
I am trying to populate text on my website from data stored in a MySQL database.
I have this script before the <head> of my HTML to establish the connection:
<?php
$username = "USERNAME";
$password = "PASSWORD";
$hostname = "127.0.0.1:3306";
//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
echo "";
//select database
$selected = mysql_select_db("Strong_Links",$dbhandle)
or die("could not select database");
?>
I have loaded that script in isolation with an echo success message, and know it works correctly.
Then, in the body of my HTML I use this script:
<?php
$result = mysql_query("SELECT content FROM web WHERE id = 'news1'", $dbhandle);
if (!$result) {
die("query failed");
}
echo "<p>$result</p>";
?>
However, on the page, I get one line saying "$result" then a line break, and then another line with ""; ?>"
Does anybody know what I am doing wrong? I have checked my query on the host machine in mySQL and it works fine.