Jump to content

Delete Function Not Working


computermax2328

Recommended Posts

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;

}

?>

Link to comment
Share on other sites

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,

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.