I am trying to add a delete button to my note taking website project I am doing at school. Almost like a forum, where you would delete replies to a topic... I want to be able to delete individual notes. Currently I can delete, however it will only delete the most recent note (bottom of the notes table). How would I get it so the delete button deletes the note from the corresponding row, not just the bottom one.
The main interface (Where I believe the problem is)
$sql="SELECT noteID, title, note, timestamp FROM $tbl_name WHERE user='$currentuser' AND subject='$currentsubject'";
$result=mysql_query($sql);
?>
<table align="center" id="notes">
<tr>
<td width="10%"><strong>Title</strong></td>
<td width="10%"><strong>ID</strong></td>
<td width="50%"><strong>Note</strong></td>
<td width="10%"><strong>Time</strong></td>
<td width="10%"><strong>Delete</strong></td>
</tr>
<?php
// Start looping table row
while($rows=mysql_fetch_array($result)){
echo'
<br>
<tr>
<td>'.$rows['title'].'</td>
<td>'.$rows['noteID'].'</td>
<td>'.$rows['note'].'</td>
<td>'.$rows['timestamp'].'</td> ';
$todelete = $rows['noteID'];
$_SESSION['todelete'] = $todelete;
echo'
<td><form method="post" action="deletenote.php" ><input type="submit" name="submit" value="Delete" </td>
</tr>
';
}
ob_end_flush()
?>
mysql_queryand other functions from themysql_API are depricated. If you're learning, please learn about an API that is actually in use, like PDO (my suggestion) or mysqli_*.</form>tag. Plus,<form>cannot be made child of<table>.