Drewdle Posted January 21, 2011 Share Posted January 21, 2011 Can anyone tell me whats wrong with this: The file uploads fine, the url however does not get posted to the database? I added a 'or die' but it didn't execute...Do I need to move the query higher up the script? <?php include ('base.php'); $id = $_GET['id']; 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"], "imgs/pictures/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } $file = $_FILES["file"]["name"]; $sql = "UPDATE `chillp_security`.`staff` SET `picture` = \'imgs/pictures/$file\' WHERE `staff`.`id` = $id;"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/225162-not-storing-data/ Share on other sites More sharing options...
doddsey_65 Posted January 21, 2011 Share Posted January 21, 2011 is this the full script? because $sql is just a string. it isnt doing anything to the database. it should be a mysql_query Quote Link to comment https://forums.phpfreaks.com/topic/225162-not-storing-data/#findComment-1162890 Share on other sites More sharing options...
Drewdle Posted January 21, 2011 Author Share Posted January 21, 2011 It was defined in the included file as something else but ive changed it now incase that was the problem...still wont store the url? <?php include ('base.php'); $id = $_GET['id']; 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"], "imgs/pictures/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } $file = $_FILES["file"]["name"]; mysql_query( "UPDATE `chillp_security`.`staff` SET `picture` = \'imgs/pictures/$file\' WHERE `staff`.`id` = $id"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/225162-not-storing-data/#findComment-1162895 Share on other sites More sharing options...
litebearer Posted January 21, 2011 Share Posted January 21, 2011 mind showing ALL code (sans password, username) including base.php AND the table field names? Quote Link to comment https://forums.phpfreaks.com/topic/225162-not-storing-data/#findComment-1162917 Share on other sites More sharing options...
PFMaBiSmAd Posted January 21, 2011 Share Posted January 21, 2011 You are escaping the single-quotes in your query string. They are part of the sql syntax and I am pretty sure that you would be getting an sql error. Did you put the or die(mysql_error()); on the version of your code with mysql_query() statement in it? Quote Link to comment https://forums.phpfreaks.com/topic/225162-not-storing-data/#findComment-1162929 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.