Jump to content

Error: Query Was Empty!


Fish181

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/281412-error-query-was-empty/
Share on other sites

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());
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.