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";
}
?>
mysql_error()
aftermysql_query
and see what the error is. Also you should sanitize your input variables before adding them to queries. – Patrick Evans Aug 4 '13 at 12:05mysql_error()
to get the actual error from the database, which should give information about what the problem is. Also, please stop using themysql_*
data access library. At least upgrade tomysqli_*
or PDO instead. Use these libraries to create prepared statements instead of opening the SQL injection vulnerability that you currently have in your code. – David Aug 4 '13 at 12:05../php/bp-connectionAdmin.php
where you make a connection, that you selected proper database bymysql_select_db()
because you used only table name in your query – Wilq Aug 4 '13 at 12:20