Note that there are some explanatory texts on larger screens.

plurals
  1. POMySQL query isn't returning any results
    primarykey
    data
    text
    <p>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.</p> <p>I just want to simply return some data from a database.</p> <p>This is linked to a php file (index.php) that just includes it.</p> <pre><code>&lt;?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; ?&gt; </code></pre> <p>Only "test//test2//test3" is returned, nothing more. </p> <p>Here's my database <img src="https://i.stack.imgur.com/sT9gf.png" alt="Here&#39;s mdatabase"></p> <p>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.</p> <p>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.</p> <p>It's probably a small error but it's really bugging me Any help would be appreciated, thanks.</p> <h2>Edit</h2> <p>I placed</p> <pre><code>error_reporting(E_ALL); ini_set('display_errors',1); </code></pre> <p>at the top of my code and it returned:</p> <p>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</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload