|
I have a PHP script that displays data from mysql in a nice tabular format. I have included a link along with each row. Now what i want is that on clicking link corresponding to a row should delete the entire row from the page as well from the MySql database. This is my code so far....Please help.
************ display_notes.php *******************
<?php
$query ="SELECT date, note FROM notes";
$result = mysql_query($query);
$count=mysql_num_rows($result);
if ($count == 0) {
echo "<br><br><strong>No notes found in database</strong>";
}
else {
echo '<table style="width: 400px" align="center" border="1px">';
echo '<tr>';
echo '<td style="width: 100px"><b>Date</b></td>';
echo '<td style="width: 300px"><b>Note</b></td>';
echo '</tr>';
while (list($date, $note) = mysql_fetch_row($result)):
echo '<tr>';
echo '<td style="width: 100px">'.$date.'</td>';
echo '<td style="width: 300px">'.$note.'</td>';
echo '<td style="border: 0px">';
echo '<a href="delete_notes.php?rec=$N_ID">DELETE</td>';
echo '</tr>';
endwhile;
echo '</table>';
}
?>
************************************************** ***************
************** delete_notes.php *****************************
<?php
mysql_query("DELETE FROM notes WHERE N_ID=$N_ID");
#if (!mysql_query($sql,$conn))
#{
#die('Error: ' . mysql_error());
#}
?>
************************************************** ***************
|