Hi,
I am new to php development! I have email table in my database which has email records. On the page read_emails.php, i have two buttons, one is of Reply and second is of Delete. My delete button is not deleting the email record in the database. Please help me where i am wrong and what error i am doing in developing the delete button. The code goes as below!
require_once("admin.inc.php");
require_once("../db.php");
$id = $_GET['id'];
$q = "SELECT * FROM clf_email WHERE emailID = '$id'";
$result = mysql_query($q);
if(isset($_POST['Delete'])){
$sql = "DELETE FROM clf_email WHERE emailID = '$id'";
$result = mysql_query($sql) or mysql_error();;
$msg = 'deleted!';
}
}
?>
<form action="" method="post">
<table width="557" height="135" border="0" class="email_tbl">
<?php if(mysql_num_rows($result) < 1){
echo "<div align='center' class='err'><b>There is no data available in the database!</b></div>";
}else {
while( $row = mysql_fetch_array($result)){
?>
<tr>
<td colspan="5" id="email_txt">Date: <?php echo $row['date']; ?></td>
</tr>
<tr>
<td width="152" id="email_txt">Sender's email:</td>
<td colspan="4" id="email"><?php echo $row['email']; ?></td>
</tr>
<tr>
<td width="152" id="email_txt">Subject:</td>
<td colspan="4" id="email"><?php echo $row['subject']; ?></td>
</tr>
<tr>
<td id="email_txt">Message:</td>
<td colspan="4" rowspan="2" valign="top" id="email_txt"><?php echo $row['message']; ?></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<?php if (!$replied){ ?>
<td> </td>
<td width="152"><a href="reply_mail.php?id=<?php echo $row['emailID'];?>" >
<input type="submit" name="reply" value="Reply" class="button"></a></td>
<td width="235"><a href="read_emails.php?id=<?php echo $row['emailID'];?>" >
<input type="submit" name="Delete" value="Delete" class="cautionbutton" onClick="return(confirm('Are you sure you want to delete this email?));">delete</a></td>
<?php }else{ ?>
<!--<td width="108" id="replied_btn">Replied</td>-->
<?php }; ?>
</tr>
<?php } }; ?>
</table>