cturner Posted October 28, 2006 Share Posted October 28, 2006 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] Quote Link to comment Share on other sites More sharing options...
gmwebs Posted October 28, 2006 Share Posted October 28, 2006 $_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] Quote Link to comment Share on other sites More sharing options...
Barand Posted October 28, 2006 Share Posted October 28, 2006 [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] Quote Link to comment Share on other sites More sharing options...
gmwebs Posted October 28, 2006 Share Posted October 28, 2006 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? Quote Link to comment Share on other sites More sharing options...
Barand Posted October 28, 2006 Share Posted October 28, 2006 null = no value'' = empty stringrun 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 sety : NULLy not set[/pre] Quote Link to comment Share on other sites More sharing options...
Barand Posted October 28, 2006 Share Posted October 28, 2006 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] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.