computermax2328 Posted June 11, 2012 Share Posted June 11, 2012 Hello Again, I think I need a second set of eyes on this one. I did a couple of tests and the $id is passing as a hidden input through the form. I think there is something wrong with my delete query, but I am not really sure. The if statements are working at the end of the page, but the delete query is not happening. Take a look? <?php require("../includes/connection.php"); require("../includes/sessioncheck.php"); ?> <?php $yes = $_POST['delyes']; $no = $_POST['delno']; $id = $_POST['hiddenid']; $select = "SELECT * FROM `database` WHERE id=$id"; if (!$select) { die ("Invaild Query: " . mysql_error()); } $result = mysql_query($select); if (!$result) { echo ("Database Select Failed " . mysql_error()); } $row = mysql_fetch_array($result); if (!$row) { die ("Invaild Fetch: " . mysql_error()); } $a = $row['a']; $b = $row['b']; $c = $row['c']; $d = $row['d']; $e = $row['e']; $f = $row['f']; $g = $row['g']; $h = $row['h']; $i = $row['i']; $j = $row['j']; $k = $row['k']; $l = $row['l']; $m = $row['m']; $delid = $row['id']; ?> <?php $query = "DELETE FROM `database` WHERE `a`='$a',`b`='$b',`c`='$c',`d`='$d',`e`='$e',`f`='$f',`g`='$g',`h`='$h',`i`='$i',`j`='$j',`k`='$k',`l`='$l',`m`='$m',`id`='$delid'"; if ($yes) { mysql_query($query,$connection); header('Location: ../pages/data_DB.php'); } else { echo ("Database Delete Failed " . mysql_error()); } if (empty($yes)) { header('Location: ../pages/data_delete_list.php'); exit; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/263998-delete-function-not-working/ Share on other sites More sharing options...
marcus Posted June 11, 2012 Share Posted June 11, 2012 When dealing with multiple where clauses you need to use AND and/or OR to separate each clause. $sql = "DELETE FROM `x` WHERE `y`='z' AND `z`='y'"; Quote Link to comment https://forums.phpfreaks.com/topic/263998-delete-function-not-working/#findComment-1352935 Share on other sites More sharing options...
ZulfadlyAshBurn Posted June 11, 2012 Share Posted June 11, 2012 ps computermax2328m, do remember to place your codes in the code tags. It kinds of look "ugly" without it. Try out what mgallforever said Quote Link to comment https://forums.phpfreaks.com/topic/263998-delete-function-not-working/#findComment-1352938 Share on other sites More sharing options...
computermax2328 Posted June 11, 2012 Author Share Posted June 11, 2012 Thanks for taking a look AND thanks for the code tag tip. You see what I did there???? AND. I love code jokes. Anyway! I got something like this now. $query = "DELETE FROM `database` WHERE `a`='$a' AND `b`='$b' AND `c`='$c'"; AND I am not getting anything. Am I executing the query incorrectly? Thanks again, Quote Link to comment https://forums.phpfreaks.com/topic/263998-delete-function-not-working/#findComment-1352942 Share on other sites More sharing options...
ZulfadlyAshBurn Posted June 11, 2012 Share Posted June 11, 2012 Oh LOL! Please repost your current code. Might be a syntax error etc... Quote Link to comment https://forums.phpfreaks.com/topic/263998-delete-function-not-working/#findComment-1352944 Share on other sites More sharing options...
computermax2328 Posted June 11, 2012 Author Share Posted June 11, 2012 All of my code is posted above. I just added the ANDs in between the different delete values. Quote Link to comment https://forums.phpfreaks.com/topic/263998-delete-function-not-working/#findComment-1352946 Share on other sites More sharing options...
ZulfadlyAshBurn Posted June 11, 2012 Share Posted June 11, 2012 Turn on error reporting and if there's any error, post it here. this should be placed before any other php codes. <?php error_reporting(E_ALL); ini_set('display_errors', '1'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/263998-delete-function-not-working/#findComment-1352947 Share on other sites More sharing options...
PFMaBiSmAd Posted June 11, 2012 Share Posted June 11, 2012 The main point of using an id (identifier) for data is so that you can reference that data by its id. You should not need to use more than WHERE id=$id in the delete query. One possible reason your exiting query is not working is that some of the data values you are putting back into the WHERE clause may contain sql special characters and they are breaking the sql syntax. If this is the case, you would need to escape all that data before putting it into the where clause. It will be much simpler to just use the id in the where clause. Quote Link to comment https://forums.phpfreaks.com/topic/263998-delete-function-not-working/#findComment-1352956 Share on other sites More sharing options...
insidus Posted June 11, 2012 Share Posted June 11, 2012 You should also write exit; As exit(); Quote Link to comment https://forums.phpfreaks.com/topic/263998-delete-function-not-working/#findComment-1353024 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.