Reputation: 1
I'm trying to delete a row in a table in my database, but it isn't working... The connection works. I've echoed the table row id to ensure it is working and still it won't delete...
Let me know if you need the connection code too.
code:
<table>
<tr>
<td>Recent Posts</td>
</tr>
<?php while($row = mysql_fetch_array($result)) : ?>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['phone number']; ?></td>
<td><a href="delete2.php?id=<?php echo $row['id'];?>">Schedule</a></td>
</tr>
<?php endwhile; ?>
</table>
delete.php code:
<?php
$b=$_GET['id'];
$sql='DELETE FROM on call WHERE id=$b';
//echoing just to make sure it is working correctly...
echo $b;
?>
</br>
</br>
<a href='index2.php'>back to list</a>
Upvotes: 0
Views: 521
Reputation: 631
You did not execute your sql. mysql_query($sql); use mysql function to prevent injection.
Upvotes: 0
Reputation: 3682
I don't understand your sql syntax. if 'on call' is your table, please rename your table to on_call and so your sql should :
$sql = "DELETE FROM on_call WHERE id = '" . $b . "'";
Upvotes: 0
Reputation: 11270
You didn't execute your DELETE sql command using mysql_query
$sql = "DELETE FROM ...";
mysql_query($sql);
Please note that the mysql functions are now deprecated. Also, you should protect your code against SQL injections.
Upvotes: 3