Jump to content

PHP / MySQL / empty query


trillion

Recommended Posts

I am able to connect to the database then later in the script

I have this code:

define('SQL_PREFIX', $_POST['username']);

$calsql4 = "
CREATE TABLE `".SQL_PREFIX."_uid` (
`id` int(11) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
";

$query4 = mysql_query($calsql4, $link);

$result = mysql_query($query4) or die('Query failed: ' . mysql_error());

and when I run the script I get this error:

Query failed: Query was empty

The strange thing is that i works on my local server but not on my remote server.
There is a difference in versions:

local = 4.1.13a
remote = 4.0.18

Both PHP versions are the same. Why will this code work on my local server and not remotely? What is making the query read as empty?
Link to comment
Share on other sites

This portion of the code is wrong:
[code]$query4 = mysql_query($calsql4, $link);

$result = mysql_query($query4) or die('Query failed: ' . mysql_error());[/code]
You've already ran the query ($calsql4) and stored the results of the query in $query4. Then you are running $query4 through mysql_query, which $query4 is not query. $query4 holds the results and thus you get the [i]Query failed: Query was empty[/i] message.

So instead use this code to run the query:
[code=php:0]$result = mysql_query($calsql4, $link) or die('Query failed: ' . mysql_error());[/code]
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.