Jump to content


Photo

Error: Query was empty


  • Please log in to reply
6 replies to this topic

#1 Blip

Blip
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 27 September 2006 - 02:09 PM

Hi folks, I'm new to PHP and have been doing ASP so please bear with me I'm getting an empty query error, but I'm not trying to query the database, I'm trying to add records. Can someone tell me what Im doing wrong? It is indeed getting the info from the form and therefore getting the variable values it needs. I know this because I have a "Hello World!" print statement inside of the first "If" and it does print out, so this condidtional woks. so what's wrong? Thanks in advance

Also, not that this script lives in a folder named admin, and the database lives in a folder called database. Both are in the same level under the root folder. Is my path for the database wrong?

Here's the code

<html>
<head>
</head>
<body>
<?php
$dayname=$_POST['dayname'];
$day=intval($_POST['day']);
$month=intval($_POST['month']);
$year=intval($_POST['year']);
$title=$_POST['title'];
$description=$_POST['description'];
$cost=$_POST['cost'];
$location=$_POST['location'];
$contact=$_POST['contact'];
$type=$_REQUEST["type"];

$con = mysql_connect("mysql","username","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("Classes", $con);

if ($type == "enter")
{
print "Hello, World!";
$result = mysql_query("INSERT INTO classes (dayname, day, month, year, title, description, cost, location, contact) VALUES ('$dayname', '$day', '$month', '$year', '$title', '$description', '$cost', '$location', '$contact')");

if (!mysql_query($SQL,$con))
  {
  die('Error: ' . mysql_error());
  }
header ('location: enter.php');

}

if ($type == "edit")
{

}

if ($type == "delete")
{

}

?>
</body>
</html>

#2 wildteen88

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

Posted 27 September 2006 - 02:18 PM

Where does $SQL get set to here:
$result = mysql_query("INSERT INTO classes (dayname, day, month, year, title, description, cost, location, contact) VALUES ('$dayname', '$day', '$month', '$year', '$title', '$description', '$cost', '$location', '$contact')");

if (!mysql_query($SQL,$con))
  {
  die('Error: ' . mysql_error());
  }


#3 Blip

Blip
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 27 September 2006 - 02:23 PM

It doesn't get set. I'm lifting this code from the net but I don't really understand it

What is the first argument of this (SQL) supposed to be?
if (!mysql_query($SQL,$con))

Do i use $result instead?

Thanks

#4 acdx

acdx
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 27 September 2006 - 02:33 PM

Instead of

<?php
$result = mysql_query("INSERT INTO classes (dayname, day, month, year, title, description, cost, location, contact) VALUES ('$dayname', '$day', '$month', '$year', '$title', '$description', '$cost', '$location', '$contact')");

if (!mysql_query($SQL,$con))
{
die('Error: ' . mysql_error());
}
?>

... make it

<?php
$result = mysql_query("INSERT INTO classes (dayname, day, month, year, 
title, description, cost, location, contact) VALUES ('$dayname', '$day', '$month', 
'$year', '$title', '$description', '$cost', '$location', '$contact')") or die(mysql_error());
?>

Also check out these links

http://php.net/manua...mysql-query.php
http://php.net/manua...nction.exit.php (aka die())

.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

.


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


#5 wildteen88

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

Posted 27 September 2006 - 02:33 PM

Chnage this:
[coce]$result = mysql_query("INSERT INTO classes (dayname, day, month, year, title, description, cost, location, contact) VALUES ('$dayname', '$day', '$month', '$year', '$title', '$description', '$cost', '$location', '$contact')");

if (!mysql_query($SQL,$con))
  {
  die('Error: ' . mysql_error());
  }
to this:
$sql = "INSERT INTO classes (dayname, day, month, year, title, description, cost, location, contact) VALUES ('$dayname', '$day', '$month', '$year', '$title', '$description', '$cost', '$location', '$contact')";

mysql_query($sql, $con) or die('Error: ' . mysql_error());

DOnt just lift the code of the net. Learn and understand the code first before using it. Also code your scripts yourself. Dont do any of the copy 'n' paste malarky you dont learn as much. Just learning how to efficiently copy 'n' paste stuff.

#6 Blip

Blip
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 27 September 2006 - 02:54 PM

Hey thanks guys, that last change worked. Yeah, I'd like to have time to read a book, butn I don't have that luxury at the moment. Thanks for your help.

#7 wildteen88

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

Posted 27 September 2006 - 02:57 PM

If you dont understand a function/keyword in PHP or whatever is in the code. Imediatly go to php.net. You'll leave the site know how to use the function/keyword and when to use it etc. php.nts documentation is on of the best you'll ever come across.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users