Fish181 Posted August 20, 2013 Share Posted August 20, 2013 (edited) Hi, Here's the source code: <?php error_reporting(-1); //defines the database information needed in order to link to the database define ('DB_NAME', 'questions'); define ('DB_USER', 'root'); define ('DB_PASSWORD', ''); define ('DB_HOST', 'localhost'); //the actual link between PHP and MySQL below $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); //error just incase it doesn't work so I can tell what's wrong if (!$link) { die('Could not connect: ' . mysql_error()); } //This selects the database I want to use and links it via msq_connect $db_selected = mysql_select_db(DB_NAME, $link); //incase of an error if (!$db_selected) { die('Can\'t use ' . DB_NAME . ':'.mysql_error()); } $query = "SELECT * FROM `questions_user` ORDER BY id DESC"; $result = mysql_query($query); if (!mysql_query($value)) { die('Cannot obtain $query!' . mysql_error()); } if (mysql_num_rows == 0) { echo 'There are no queries at this time!'; die; } while($data = mysql_fetch_row($result)){ echo $data; } mysql_close(); ?> When I load the page I get a "query was empty" error. The DB name is questions The DB table is questions_user The DB fields are `ID` and `questions_field` This is some of the first interactive things i've made combining mysql and php. I know the code is probably sloppy. Thanks for helping me out, Fisher P.S. I'm trying to output the data from 'questions_user' to just a random spot on a webpage. Edited August 20, 2013 by Fish181 Quote Link to comment https://forums.phpfreaks.com/topic/281412-error-query-was-empty/ Share on other sites More sharing options...
Barand Posted August 20, 2013 Share Posted August 20, 2013 (edited) Look at your variables $query = "SELECT * FROM `questions_user` ORDER BY id DESC";$result = mysql_query($query);if (!mysql_query($value)) { die('Cannot obtain $query!' . mysql_error());} Change to if (!$result) { die('Cannot obtain $query!' . mysql_error()); } Edited August 20, 2013 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/281412-error-query-was-empty/#findComment-1446043 Share on other sites More sharing options...
Fish181 Posted August 21, 2013 Author Share Posted August 21, 2013 thanks! Quote Link to comment https://forums.phpfreaks.com/topic/281412-error-query-was-empty/#findComment-1446051 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.