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.

Edited by Fish181
Link to comment
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());
}
Edited by Barand
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.