Jump to content

[SOLVED] PHP MySQL Empty Query Help


crochk

Recommended Posts

I have a form to submit information on an event, including a logo (file).  This information would then be submitted into a MySQL database.

When the form is filled out, an "empty query" error is returned.

But the file is put into the correct directory, just nothing is submitted into the database.

 

Here is my php code for processing the form:

<?php
	if (isset($_POST['submit']))
		{
		if ($_FILES['file']['size'] > 0)
    			{
 $con = mysql_connect("localhost","XXXXXXXXXX","XXXXXXXXXXX");
            if (!$con)
              {
              die('Could not connect: ' . mysql_error());
              }
            
            mysql_select_db("XXXXXXXXXXXX", $con);
			//Delcarations
			putenv("TZ=US/Eastern");
	$uploadDir = '/XXXXXXXXXXXXXXXXXXXX/htdocs/events/images/logos/';
			$ip=$_SERVER['REMOTE_ADDR'];
			$date=date("d-M-Y h:i:s A");

			//POSTS
$name = $_POST['name'];
$where = $_POST['where'];
$when = $_POST['when'];
$age = $_POST['age'];
$price = $_POST['price'];
$description = $_POST['description'];
$minidescription = $_POST['minidescription'];
$facebook = $_POST['facebook'];
$dateorder = $_POST['dateorder'];

			//File
			$filename = $_FILES['file']['name'];
			$tmpname = $_FILES['file']['tmp_name'];
			$filesize = $_FILES['file']['size'];
			$filetype = $_FILES['file']['type'];
			$file=$_POST[file];

			$ext = substr(strrchr($filename, "."), 1);
			$randName = md5(rand() * time());
			$filepath = $uploadDir . $randName . '.' . $ext;

			$result = move_uploaded_file($tmpname, $filepath);

			if(!get_magic_quotes_gpc())
			{
			$filename = addslashes($filename);
			$filepath = addslashes($filepath);
			}

			$usePath="http://XXXXXXXXXXXXXXXX/events/images/logos/" . $randName . '.' . $ext;



			//Insert into DB
	$sql=mysql_query("INSERT INTO events (name, where, when, age, price, description, minidescription, facebook, dateorder, filepath, filename, filetype, filesize, ip, date)
		VALUES
		('$name','$where','$when','$age','$price','$description','$minidescription','$facebook','$dateorder','$usePath','$fileName','$fileType','$fileSize','$ip','$date')");

if (!mysql_query($sql1,$con))
			 {
			 die('<p><strong>Event:</strong> Error Uploading</p><p>Error: ' . mysql_error() . '</p>');
			}

		echo "<p><strong>" . $name . " Submitted</strong></p>";


			}
		else
			{
			die("No Logo Submitted");
			}
		}
	else
		{
?>

 

Thanx

Link to comment
Share on other sites

I did try it, so unless I missunderstood your correction, it still doesnt work

 

here is the corrected code:

<?php
	if (isset($_POST['submit']))
		{
		if ($_FILES['file']['size'] > 0)
    			{
 $con = mysql_connect("localhost","XXXXXXXXXX","XXXXXXXXXXX");
            if (!$con)
              {
              die('Could not connect: ' . mysql_error());
              }
            
            mysql_select_db("XXXXXXXXXXXX", $con);
			//Delcarations
			putenv("TZ=US/Eastern");
	$uploadDir = '/XXXXXXXXXXXXXXXXXXXX/htdocs/events/images/logos/';
			$ip=$_SERVER['REMOTE_ADDR'];
			$date=date("d-M-Y h:i:s A");

			//POSTS
$name = $_POST['name'];
$where = $_POST['where'];
$when = $_POST['when'];
$age = $_POST['age'];
$price = $_POST['price'];
$description = $_POST['description'];
$minidescription = $_POST['minidescription'];
$facebook = $_POST['facebook'];
$dateorder = $_POST['dateorder'];

			//File
			$filename = $_FILES['file']['name'];
			$tmpname = $_FILES['file']['tmp_name'];
			$filesize = $_FILES['file']['size'];
			$filetype = $_FILES['file']['type'];
			$file=$_POST[file];

			$ext = substr(strrchr($filename, "."), 1);
			$randName = md5(rand() * time());
			$filepath = $uploadDir . $randName . '.' . $ext;

			$result = move_uploaded_file($tmpname, $filepath);

			if(!get_magic_quotes_gpc())
			{
			$filename = addslashes($filename);
			$filepath = addslashes($filepath);
			}

			$usePath="http://XXXXXXXXXXXXXXXX/events/images/logos/" . $randName . '.' . $ext;



			//Insert into DB
	$sql=mysql_query("INSERT INTO events (name, where, when, age, price, description, minidescription, facebook, dateorder, filepath, filename, filetype, filesize, ip, date)
		VALUES
		('$name','$where','$when','$age','$price','$description','$minidescription','$facebook','$dateorder','$usePath','$fileName','$fileType','$fileSize','$ip','$date')");

if (!mysql_query($sql,$con))
			 {
			 die('<p><strong>Event:</strong> Error Uploading this event</p><p>Error: ' . mysql_error() . '</p>');
			}

		echo "<p><strong>" . $name . " Submitted</strong></p>";


			}
		else
			{
			die("No Logo Submitted");
			}
		}
	else
		{
?>

Link to comment
Share on other sites

I understand what you are saying, but I am still getting another error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where, when, age, price, description, minidescription, facebook, dateorder, file' at line 1

 

New code:

<?php
	if (isset($_POST['submit']))
		{
		if ($_FILES['file']['size'] > 0)
    			{
 $con = mysql_connect("localhost","XXXXXXXXXX","XXXXXXXXXXX");
            if (!$con)
              {
              die('Could not connect: ' . mysql_error());
              }
            
            mysql_select_db("XXXXXXXXXXXX", $con);
			//Delcarations
			putenv("TZ=US/Eastern");
	$uploadDir = '/XXXXXXXXXXXXXXXXXXXX/htdocs/events/images/logos/';
			$ip=$_SERVER['REMOTE_ADDR'];
			$date=date("d-M-Y h:i:s A");

			//POSTS
$name = $_POST['name'];
$where = $_POST['where'];
$when = $_POST['when'];
$age = $_POST['age'];
$price = $_POST['price'];
$description = $_POST['description'];
$minidescription = $_POST['minidescription'];
$facebook = $_POST['facebook'];
$dateorder = $_POST['dateorder'];

			//File
			$filename = $_FILES['file']['name'];
			$tmpname = $_FILES['file']['tmp_name'];
			$filesize = $_FILES['file']['size'];
			$filetype = $_FILES['file']['type'];
			$file=$_POST[file];

			$ext = substr(strrchr($filename, "."), 1);
			$randName = md5(rand() * time());
			$filepath = $uploadDir . $randName . '.' . $ext;

			$result = move_uploaded_file($tmpname, $filepath);

			if(!get_magic_quotes_gpc())
			{
			$filename = addslashes($filename);
			$filepath = addslashes($filepath);
			}

			$usePath="http://XXXXXXXXXXXXXXXX/events/images/logos/" . $randName . '.' . $ext;



			//Insert into DB
	$sql=mysql_query("INSERT INTO events (name, where, when, age, price, description, minidescription, facebook, dateorder, filepath, filename, filetype, filesize, ip, date)
		VALUES
		('$name','$where','$when','$age','$price','$description','$minidescription','$facebook','$dateorder','$usePath','$fileName','$fileType','$fileSize','$ip','$date')");

if (!$sql)
			 {
			 die('<p><strong>Event:</strong> Error Uploading</p><p>Error: ' . mysql_error() . '</p>');
			}

		echo "<p><strong>" . $name . " Submitted</strong></p>";


			}
		else
			{
			die("No Logo Submitted");
			}
		}
	else
		{
?>

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.