Jump to content


Photo

Unknown column 'Array' in 'field list'


  • Please log in to reply
5 replies to this topic

#1 cturner

cturner
  • Members
  • PipPipPip
  • Advanced Member
  • 148 posts
  • LocationMy computer

Posted 28 October 2006 - 09:40 PM

I am getting the following error when I test the code that is below:
Could not add the entry because: Unknown column 'Array' in 'field list'. The query was INSERT INTO tbl_testing (id, photo) VALUES (0, Array).
Can someone please help me solve this error? Thanks in advance.

require "config.php";
if (isset($_POST['Submit'])) {
	$path = $_FILES['path'];
	$insert = "INSERT INTO tbl_testing (id, photo) VALUES (0, $path)";
		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();

Here is the form:
<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%">File path</td>
      <td width="85%"><input name="path" type="file" id="path"></td>
    </tr>
    <tr>
      <td colspan="2"><input type="submit" name="Submit" value="SUBMIT" id="Submit"></td>
    </tr>
  </table>
</form>


#2 gmwebs

gmwebs
  • Members
  • PipPipPip
  • Advanced Member
  • 174 posts
  • LocationLondon

Posted 28 October 2006 - 09:55 PM

$_FILES is an array.

I think you are going about things a little wrong. When you submit a file from a form, it is first copied to a temporary location. You then need to move this temp file to the folder you wish to store the file in. That temporary location is stored in the $_FILES['uploadedfile']['tmp_name']. Have a look at this link which explains things quite nicely, and provides some demo scripts too.

Also, if the id column in your tbl_testing table is an autoincrement field, then you would want to insert an empty value and not a 0.

<?php

$path = "path/to/uploads";

$insert = "INSERT INTO tbl_testing (id, photo) VALUES ('', $path)";
?>


#3 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,025 posts

Posted 28 October 2006 - 10:12 PM

Also, if the id column in your tbl_testing table is an autoincrement field, then you would want to insert an empty value and not a 0.


Actually you should specify null or omit the column completely from the query. String values should be quoted.

<?php
$insert = "INSERT INTO tbl_testing (id, photo) VALUES (null, '$path')";
 // or
$insert = "INSERT INTO tbl_testing (photo) VALUES ('$path')";
?>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#4 gmwebs

gmwebs
  • Members
  • PipPipPip
  • Advanced Member
  • 174 posts
  • LocationLondon

Posted 28 October 2006 - 10:16 PM

mmmm.... never knew that Barand... In all my scripts I have always used 2 single quotes with nothing in between. Does that not mean null?

#5 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,025 posts

Posted 28 October 2006 - 10:34 PM

null = no value
'' = empty string

run this
<?php
$x = '';
$y = null;
    
echo '<pre>';

echo 'x : ';
var_dump ($x);

if (isset($x)) 
    echo "x is set\n";
else
    echo "x not set\n";
echo "\n\n";    
echo 'y : ';
var_dump ($y);

if (isset($y)) 
    echo "y is set\n";
else
    echo "y not set\n";
    
echo '</pre>';


?>

Gives -->
[pre]
x : string(0) ""
x is set


y : NULL
y not set


[/pre]
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#6 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,025 posts

Posted 28 October 2006 - 11:44 PM

I had another read of the manual re auto_increment columns

the value is automatically generated by storing the special values NULL or 0 into the column


If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users