craigeves Posted March 26, 2010 Share Posted March 26, 2010 Hi I wonder if someone can help? I want to upload an image to my server - then store the URL in my database table ' gallery'. Upload part works perfect... it's just the storing of the URL in the table that stores a blank entry. Can someone see where im going wrong? Thanks Craig <?php require_once('../Connections/hairstation.php'); mysql_select_db($database_hairstation, $hairstation); $query_gallery = "SELECT * FROM gallery"; $gallery = mysql_query($query_gallery, $hairstation) or die(mysql_error()); $row_gallery = mysql_fetch_assoc($gallery); $totalRows_gallery = mysql_num_rows($gallery); ?> <?php if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 20000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; //Writes the information to the database mysql_query("INSERT INTO `gallery` (file) VALUES ('$file')") or die(mysql_error()); } } } else { echo "Invalid file"; } ?> Link to comment https://forums.phpfreaks.com/topic/196583-upload-image-and-store-url-in-database/ Share on other sites More sharing options...
AdRock Posted March 26, 2010 Share Posted March 26, 2010 you need to put something like $files = $_FILES["file"]["name"] ; Just after the file has uploaded. You are passsing an empty variable to the database Link to comment https://forums.phpfreaks.com/topic/196583-upload-image-and-store-url-in-database/#findComment-1032157 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.