Jump to content

Archived

This topic is now archived and is closed to further replies.

cturner

Unknown column 'Array' in 'field list'

Recommended Posts

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.

[code]
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();
[/code]

Here is the form:
[code]
<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>
[/code]

Share this post


Link to post
Share on other sites
$_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 [url=http://www.tizag.com/phpT/fileupload.php]this[/url] 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.

[code]
<?php

$path = "path/to/uploads";

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

Share this post


Link to post
Share on other sites
[quote]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.[/quote]

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

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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
null = no value
'' = empty string

run this
[code]
<?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>';


?>[/code]

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


y : NULL
y not set


[/pre]

Share this post


Link to post
Share on other sites
I had another read of the manual re auto_increment columns
[quote]
the value is automatically generated by storing the special values NULL or 0 into the column
[/quote]

Share this post


Link to post
Share on other sites

×

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.