justAnoob Posted May 23, 2009 Share Posted May 23, 2009 trying to delete the image path from mysql..... It deletes it from the server directory but it won't delete the path from mysql... <?php //error_reporting(E_ALL); //ini_set('display_errors',1); session_start(); require 'connection.php'; $id_gone = $_SESSION['move_id']; //id of image $image5 = $_SESSION['path_5']; //path to image unlink($image5); mysql_query("DELETE imgpath5 FROM abcxyz WHERE id = '$id_gone'"); echo "image deleted."; echo "$id_gone"; //both variables echo,, so I know there working. echo "$image5"; ?> I tried using different variables(the 2 above) after the WHERE in the query to make it work,, but nothing. Link to comment https://forums.phpfreaks.com/topic/159349-solved-what-am-i-doing-wrong/ Share on other sites More sharing options...
MasterACE14 Posted May 23, 2009 Share Posted May 23, 2009 imgpath5 needs to be in the WHERE claus Link to comment https://forums.phpfreaks.com/topic/159349-solved-what-am-i-doing-wrong/#findComment-840472 Share on other sites More sharing options...
RussellReal Posted May 23, 2009 Share Posted May 23, 2009 ace, it doesn't HAVE to be, if the id corresponds to the result in the database, then it should work regardless.. do this noob <?php session_start(); require('connection.php'); $id = $_SESSION['move_id']; print_r(mysql_fetch_assoc(mysql_query("SELECT * FROM `abcxyz` WHERE `id` = '{$id}'"))); ?> and tell me what you get Link to comment https://forums.phpfreaks.com/topic/159349-solved-what-am-i-doing-wrong/#findComment-840475 Share on other sites More sharing options...
justAnoob Posted May 23, 2009 Author Share Posted May 23, 2009 Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in something is wrong with the synyax in the print line yes,,, i changed to crazy looking single quotes to regular single quotes.. Link to comment https://forums.phpfreaks.com/topic/159349-solved-what-am-i-doing-wrong/#findComment-840476 Share on other sites More sharing options...
Ken2k7 Posted May 23, 2009 Share Posted May 23, 2009 <?php //error_reporting(E_ALL); //ini_set('display_errors',1); session_start(); require 'connection.php'; $id_gone = $_SESSION['move_id']; //id of image $image5 = $_SESSION['path_5']; //path to image unlink($image5); $result = mysql_query("DELETE FROM abcxyz WHERE id = '$id_gone'"); if ($result) echo "image deleted."; ?> OR <?php //error_reporting(E_ALL); //ini_set('display_errors',1); session_start(); require 'connection.php'; $id_gone = $_SESSION['move_id']; //id of image $image5 = $_SESSION['path_5']; //path to image unlink($image5); $result = mysql_query("UPDATE abcxyz SET imgpath5 = '' WHERE id = '$id_gone'"); if ($result) echo "image deleted."; ?> Link to comment https://forums.phpfreaks.com/topic/159349-solved-what-am-i-doing-wrong/#findComment-840477 Share on other sites More sharing options...
justAnoob Posted May 23, 2009 Author Share Posted May 23, 2009 I'll try using the UPDATE..... Link to comment https://forums.phpfreaks.com/topic/159349-solved-what-am-i-doing-wrong/#findComment-840479 Share on other sites More sharing options...
RussellReal Posted May 23, 2009 Share Posted May 23, 2009 you are not connecting to your database, or the query returns nothing.. Link to comment https://forums.phpfreaks.com/topic/159349-solved-what-am-i-doing-wrong/#findComment-840481 Share on other sites More sharing options...
justAnoob Posted May 23, 2009 Author Share Posted May 23, 2009 I am including the connection.php which connects. Link to comment https://forums.phpfreaks.com/topic/159349-solved-what-am-i-doing-wrong/#findComment-840489 Share on other sites More sharing options...
Ken2k7 Posted May 23, 2009 Share Posted May 23, 2009 Let's test that. <?php //error_reporting(E_ALL); //ini_set('display_errors',1); session_start(); require 'connection.php'; $id_gone = $_SESSION['move_id']; //id of image $image5 = $_SESSION['path_5']; //path to image unlink($image5); $result = mysql_query("UPDATE abcxyz SET imgpath5 = '' WHERE id = '$id_gone'") or die(mysql_error()); if ($result) echo "image deleted."; ?> Link to comment https://forums.phpfreaks.com/topic/159349-solved-what-am-i-doing-wrong/#findComment-840490 Share on other sites More sharing options...
justAnoob Posted May 23, 2009 Author Share Posted May 23, 2009 Think I got it Ken2k7,, something similar to what you have just posted... Let you know in a while. Link to comment https://forums.phpfreaks.com/topic/159349-solved-what-am-i-doing-wrong/#findComment-840491 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.