I have been trying to do this for a day or two now and just can't understand why it isn't working as I have others set up in the same way.
I just want to simply return some data from a database.
This is linked to a php file (index.php) that just includes it.
<?php
/*connect to local database */
$host="localhost"; // Host name
$db_username="Josh"; // Mysql username
$db_password="password"; // Mysql password
$db_name="messenger"; // Database name
$tbl_name="messages"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$db_username", "$db_password")or die("cannot connect to database");
mysql_select_db("$db_name")or die("cannot select DB");
$con=mysql_connect("$host","$db_username","$db_password","$db_name");
echo "test";
//retrieve messages
$query = mysql_query($con, "SELECT * FROM messages WHERE key='Josh'") or die(mysql_error());
echo "test2";
$row = mysql_fetch_assoc($query);
$msg = $row['msg_array'];
echo "test3";
echo mysql_num_rows($query);
echo $msg;
?>
Only "test//test2//test3" is returned, nothing more.
Here's my database
I've been trying to simply get something returned for hours and am getting a tad annoyed. I've had loads of errors as I've been changing it but this time, nothing's returned.
This should work as I've returned data multiple times and know how to do it from scratch. All of my other sites work properly and I haven't updated phpMyAdmin either.
It's probably a small error but it's really bugging me Any help would be appreciated, thanks.
Edit
I placed
error_reporting(E_ALL);
ini_set('display_errors',1);
at the top of my code and it returned:
test//test2// Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\Users\Josh\SkyDrive\Default Sync Folder\Websites\IM\global.php on line 22 test3 Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\Users\Josh\SkyDrive\Default Sync Folder\Websites\IM\global.php on line 26