techker Posted March 15, 2008 Share Posted March 15, 2008 ok i have a question concerning the get variable. i have this script that is used to post pics with descriptions and prices. now the uploading side uses es if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) so it stores the image in a folder and links it to a description store in my database. now i can delete the info no prob in the database the only thing is the pic that was uploaded isn't deleted at the same time. so i did my research and found the unlink function. $file = "pic name"; if (!unlink($file)) { echo ("Error deleting $file"); } else { echo ("Deleted $file"); } now i know i can do it.but im not shure how. so i did a link on that description page to delete the db and another to delete the pic <a href="deleter_pic.php?photo=<?php echo $info['photo'] ?>">Delete</a></td> so basicly this <?php echo $info['photo'] ?> shows the pic name in the url bar. from the help of the data base. now i know i can go get it with $_GET['photo'] witch will read the info on the url (photo is the name of the pic from db) 1rst question why do i get a 500 page? 2nd question is there a way to do this without a db? like when you click on the pic it does the same as my delete link without the help of the database to show the pic name? and on the delete page in the filename to delete how would it read the url? or is there an easer way? is it clear ?lol thx for the help Reply With Quote Quote Link to comment https://forums.phpfreaks.com/topic/96271-_get/ Share on other sites More sharing options...
wildteen88 Posted March 15, 2008 Share Posted March 15, 2008 You can delete the image from the database and the filesystem at the same time. On the page that deletes the image from the database I assume you provide some form of image id, ie your link will be delete.php?image_id=xxx (xxx representing a number which is associated to the image stored in the database). If thats the case, then before you delete the image from the database then do a simple database query to return the image from the database, then delete the image from filesystem using unlink and run another query to delete the image from the database. $imageID = $_GET['image_id']; $qry = "SELECT image_path FROM image_table WHERE image_id='$imageID'"; list($image_path) = mysql_fetch_row(mysql_query($qry)); // delete image unlink($image_path); // delete image from database; mysql_query("DELETE FROM image_table WHERE image_id='$imageID'"); Quote Link to comment https://forums.phpfreaks.com/topic/96271-_get/#findComment-493098 Share on other sites More sharing options...
discomatt Posted March 15, 2008 Share Posted March 15, 2008 list($image_path) = mysql_fetch_row(mysql_query($qry)); can be replaced with $image_path = mysql_result(mysql_query($qry), 0); Quote Link to comment https://forums.phpfreaks.com/topic/96271-_get/#findComment-493100 Share on other sites More sharing options...
techker Posted March 16, 2008 Author Share Posted March 16, 2008 i don't have an id but i have an inventory number. so in the database i don't know if it store the path? here is the add script. <?php $target = "images/big/"; $target2= "images/thumbs/"; $target3= "images/pics/"; $target = $target . basename( $_FILES['photo']['name']); $target2 = $target2 . basename( $_FILES['thumb']['name']); $target3 = $target3 . basename( $_FILES['pics']['name']); $3 =$_POST['3mois']; $6 =$_POST['6mois']; $12 =$_POST['12mois']; //$pic=($_FILES['photo']['name']); //$thumb=($_FILES['thumb']['name']); $15 =$_POST['15mois']; //$desc=$_POST['description']; //$pics=($_FILES['pics']['name']); // Connects to your Database mysql_connect("localhost", "techker_techker", "techker") or die(mysql_error()) ; mysql_select_db("techker_techker") or die(mysql_error()) ; //Writes the information to the database mysql_query("INSERT INTO `hours` VALUES ('$3', '$6', '$12', '$15')") ; //if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) //{ //if(move_uploaded_file($_FILES['thumb']['tmp_name'], $target2)) //{ //if(move_uploaded_file($_FILES['pics']['tmp_name'], $target3)) //{ //echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; echo "You'll be redirected to Home Page after (4) Seconds"; echo "<meta http-equiv=Refresh content=4;url=index.php>"; } else { echo "Sorry, there was a problem uploading your file."; } //} //} ?> it's a good idea do to delete all at the same time.and by getting the path Quote Link to comment https://forums.phpfreaks.com/topic/96271-_get/#findComment-493317 Share on other sites More sharing options...
wildteen88 Posted March 16, 2008 Share Posted March 16, 2008 That script will not work. You cannot use variable names that start with numbers. Also no where in that script you appear to add the image to the database. Quote Link to comment https://forums.phpfreaks.com/topic/96271-_get/#findComment-493328 Share on other sites More sharing options...
techker Posted March 16, 2008 Author Share Posted March 16, 2008 well it works perfectly and like i said it does not put images in the database it move it to a folder if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) but i relly would like to store in a databse cause it would be lot more simpler..lol but i have tryed almost every tutorial out there with no success.. Quote Link to comment https://forums.phpfreaks.com/topic/96271-_get/#findComment-493338 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.