Search code examples
phpmysqldelete-rowcorresponding-records

Not delete specified content from mysql


I've recently made a PHP, that should; if click a link delete a certain row within one of my MYSQL tables.

The script below has everything but the link [href=delete_ac.php?id etc...] leads to the page but when the page activates it echo ERROR instead of deleting the row.

<h1>Members</h1> 
<table> 
    <tr> 
        <th>ID</th> 
        <th>Username</th> 
        <th>E-Mail Address</th> 
        <th></th>
    </tr> 
    <?php foreach($rows as $row): ?> 
        <tr> 
            <td><?php echo $row['id']; ?></td> 
            <td><?php echo htmlentities($row['username'], ENT_QUOTES, 'UTF-8'); ?></td> 
            <td><?php echo htmlentities($row['email'], ENT_QUOTES, 'UTF-8'); ?></td> 
            <td><a href="delete_ac.php?id=<?php echo $row['id']; ?>">delete</a></td> 
        </tr> 
    <?php endforeach; ?> 
</table>

delete_ac.php The script below is what should delete it but it isn't

<?php

    require("../php/bp-connectionAdmin.php");

    $id=$_GET['id'];

    $query = "DELETE FROM `users` WHERE `id` = $id";
    $result = mysql_query($query);

   if ($result) {
        echo "Successful";
   } else {
        echo "ERROR";
   }
?> 

Solution

  • Is the ID numeric only? Would the addition of quote marks around $id not help?

    $query = "DELETE FROM `users` WHERE `id`='$id'";
    mysql_query($query);
    

    Not sure...but give it a go!