Could not add the entry???

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
cturner
Forum Contributor
Posts: 153
Joined: Sun Jul 16, 2006 3:03 am
Location: My computer

Could not add the entry???

Post 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>
printf
Forum Contributor
Posts: 173
Joined: Wed Jan 12, 2005 5:24 pm

Post 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
User avatar
cturner
Forum Contributor
Posts: 153
Joined: Sun Jul 16, 2006 3:03 am
Location: My computer

Post 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();
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Take a look at what's inside $_FILES.
Post Reply