Page 1 of 1

Could not add the entry???

Posted: Fri Oct 27, 2006 7:03 pm
by cturner
I am getting the following when I test the code that is below:
Could not add the entry because: 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 ' )' at line 1. The query was INSERT INTO tbl_testing (id, photo, phototype) VALUES (0, , ). Can someone please help me solve this problem? Thanks in advance.

Here is the code for adding a filename to the database:

Code: Select all

require "config.php";
if (isset($_POST['Submit'])) {
	$filename = $_POST['filename'];
	$type = filetype($filename);
	$insert = "INSERT INTO tbl_testing (id, photo, phototype) VALUES (0, $filename, $type)";
		if (mysql_query($insert)) {
			header ('Location: tested.php');
		} else {
			print "<p>Could not add the entry because: <b>" . mysql_error() . "</b>. The query was $insert.</p>";
		}
}
mysql_close();
This is the form:

Code: Select all

<form action="<?php echo $PHP_SELF; ?>" method="post" enctype="multipart/form-data" name="testingform">
  <table width="100%"  border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td width="15%">Filename</td>
      <td width="85%"><input name="filename" type="file" id="filename"></td>
    </tr>
    <tr>
      <td colspan="2"><input type="submit" name="Submit" value="SUBMIT" id="Submit"></td>
    </tr>
  </table>
</form>

Posted: Fri Oct 27, 2006 7:41 pm
by printf
a file upload will not be part of the $_POST array, it will be found in the $_FILES array, and don't use filetype() as it does not tell you the mime type, it only tells you the system type (dir, file, ...). Also what do you want to do with the file you are uploading!

printf

Posted: Fri Oct 27, 2006 7:49 pm
by cturner
I have changed the $_POST to $_FILES and now I am getting this error when I press the submit button:
Could not add the entry because: Unknown column 'Array' in 'field list'. The query was INSERT INTO tbl_testing (id, photo) VALUES (0, Array).

Here is the updated code:

Code: Select all

require "config.php";
if (isset($_POST['Submit'])) {
	$filename = $_FILES['filename'];
	$insert = "INSERT INTO tbl_testing (id, photo) VALUES (0, $filename)";
		if (mysql_query($insert)) {
			header ('Location: tested.php');
		} else {
			print "<p>Could not add the entry because: <b>" . mysql_error() . "</b>. The query was $insert.</p>";
		}
}
mysql_close();

Posted: Fri Oct 27, 2006 7:54 pm
by feyd
Take a look at what's inside $_FILES.