Hope someone can help... I am able to upload an image to the server using PHP by what I am then trying to do is to add the image name on to a MySQL database. An example of what I am trying to do is shown below: Form element: <input name="fileupload" type="file" size="50"> PHP element: $insert = mysql_query("insert into table values ('$_POST[fileupload]')"); Is it not possible to insert an image file name direct in to a MySQL database using $_POST ? Is there another way? Thanks!
Use $_FILES['fileupload']['name']. This will hold the name of the file. And also have a look at www.php.net/mysql_real_escape_string to avoid SQL injection.
Thanks nico for your help...much appreciated. I have had a little play around (because I use more than one image to be uploaded in one form) but will try and have another play aorund to see if i can work this out. Do you mean: $insert = mysql_query("insert into table values ('$_FILES['fileupload']['name']')"); or $imagename = $_FILES['fileupload']['name'] $insert = mysql_query("insert into table values ('$imagename')"); Cheers!
The first would throw a syntax error. I'd do it like that $insert = mysql_query(" INSERT INTO table VALUES ('" . mysql_real_escape_string($_FILES['fileupload']['name']) . "') ") OR die(mysql_error()); PHP: