Jump to content


Photo

PHP / MySQL / empty query


  • Please log in to reply
5 replies to this topic

#1 trillion

trillion
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 16 September 2006 - 07:36 AM

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?

#2 markbett

markbett
  • Members
  • PipPipPip
  • Advanced Member
  • 133 posts

Posted 16 September 2006 - 07:49 AM

have it echo your query.... see what it is trying to post

#3 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 16 September 2006 - 12:05 PM

You run the query CREATE TABLE twice. The second line should maybe a test for the result of the create

Ronald  8)

RTFM is an almost extinct art form, it should be subsidized.

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 16 September 2006 - 01:12 PM

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

$result = mysql_query($query4) or die('Query failed: ' . mysql_error());
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 Query failed: Query was empty message.

So instead use this code to run the query:
$result = mysql_query($calsql4, $link) or die('Query failed: ' . mysql_error());


#5 trillion

trillion
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 16 September 2006 - 06:07 PM

OK

I see the problem with my pervious code and have changed it as suggested above however I am still receiving the Query Failed: Query was empty error message.

#6 trillion

trillion
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 16 September 2006 - 08:05 PM

I found the problem

the local server would accept the query as MyISAM but the remote server would not.

By removing the line below from all my queries I got the script to work.

ENGINE=MyISAM DEFAULT CHARSET=latin1




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users