I have a code to upload an image, it works just fine. The problem I am having is that I can’t seem to get the file name inserted into the database. When I execute the script without the code to insert into mysql db it runs fine, but with it, the page goes blank. Can someone help me out? This is the code.
$con=mysqli_connect("localhost","user","***","db");
// Check connectionif (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); }
mysqli_query($con,"INSERT INTO image (image) VALUES ('$_FILES['image']['name']')");
mysqli_close($con);
The first thing I would try is putting the file name into a variable and echoing it out to see it contains what you expect and then use that variable in your insert.
I always try and keep things simple and you can always make it more streamlined when its working.
Well I did what you said, no luck. I’ve been scouring the web and altering the code a little here and there, but no luck. I wonder if it is the placement within the code? I’ve included the full page.
is treated as ‘$_FILES[’ as a string then image as invalid and so stopping the query running then ‘][’ as a string then name as invalid which would also stop the script running then ‘]’ as a string
if you change it to:
‘“.$_FILES[‘image’][‘name’].”’
(that’s ’ then " at the start and " then ’ at the end) then the quotes will match up properly.