Jump to content

Unknown column 'Array' in 'field list'


cturner

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]
Link to comment
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]
Link to comment
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]
Link to comment
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]
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.