Hello,
I am trying to create a messaging system inter-user within the same website.
1 message_id int(4)
2 from_stu_username varchar(30)
3 date datetime
4 messages varchar(200)
5 to_stu_username varchar(30)
admin/messages.php
//Hapus berita // undefined index: mode
if (!empty($_REQUEST['message_id']))
{
$message_id = $_REQUEST['message_id'];
$result = mysql_query("DELETE FROM messages WHERE message_id =".$message_id) or die(mysql_error());
$confirmation = !$result ? "Gagal menghapus data." : "Data telah terhapus.";
}
?>
<div align="center">
<div style="width:700px;text-align:left;padding-top:5px;">
<?php if (isset($confirmation)) { echo $confirmation; } ?>
<form method="get" action="<?php $_SERVER['PHP_SELF'] ?>">
<br/>
<button type="button" onClick="parent.location='add_message.php'">Compose</button><br><br>
<?php
//LOAD INBOX MESSAGES
// pagination references:
// http://www.raymondselda.com/php-pagination-script/
//Include the PS_Pagination class
include('ps_pagination.php');
//Connect to mysql db
$conn = mysql_connect('localhost','root','');
mysql_select_db('squprime',$conn);
$sql = "SELECT * FROM messages WHERE to_stu_username='".$_SESSION['username']."' ORDER BY date" or die(mysql_error());
//Create a PS_Pagination object
$pager = new PS_Pagination($conn,$sql,10,10);
$result = $pager->paginate();
?>
<table id="admintable" border="1" cellpadding="2" cellspacing="0" width="900px">
<tr>
<b>Inbox</b><br><br>
<th>From</th><th style="width:500px;">Messages</th><th>Date</th>
</tr>
<?php
$i=0;
while ($data = mysql_fetch_array($result)){
$result2=($i%2)?'#DFA09D':'white';
echo "<tr bgcolor='$result2'>";
echo '<td>'.$data['from_stu_username'].'</td>';
echo '<td>'.$data['messages'].'</td>';
echo '<td>'.$data['date'].'</td>';
echo '<td><center><a href="messages.php?message_id='.$data['message_id'].'" onClick="return confirm(\'Are you sure you want to delete this?\')">Delete</center></td>';
echo '</tr>';
$i++;
}
?>
</table>
<?php //Display the full navigation in one go
echo '<br><br>';
echo $pager->renderFullNav();
?>
<?php
//LOAD OUTBOX MESSAGES
// pagination references:
// http://www.raymondselda.com/php-pagination-script/
//Connect to mysql db
$conn = mysql_connect('localhost','root','');
mysql_select_db('squprime',$conn);
$sql = "SELECT * FROM messages WHERE from_stu_username='".$_SESSION['username']."' ORDER BY date";
//Create a PS_Pagination object
$pager = new PS_Pagination($conn,$sql,5,5);
$result = $pager->paginate();
?>
<table id="admintable" border="1" cellpadding="2" cellspacing="0" width="900px">
<tr>
<br><br><b>Sent</b><br><br>
<th>To</th><th style="width:500px;">Messages</th><th>Date</th>
</tr>
<?php
$i=0;
while ($data = mysql_fetch_array($result)){
$result2=($i%2)?'#DFA09D':'white';
echo "<tr bgcolor='$result2'>";
echo '<td>'.$data['to_stu_username'].'</td>';
echo '<td>'.$data['messages'].'</td>';
echo '<td>'.$data['date'].'</td>';
echo '<td><center><a href="messages.php?message_id='.$data['message_id'].'" onClick="return confirm(\'Are you sure you want to delete this?\')">Delete</center></td>';
echo '</tr>';
$i++;
}
?>
</table>
<?php //Display the full navigation in one go
echo '<br><br>';
echo $pager->renderFullNav();
?>
</form>
</div>
</div>
</center>
</div>
<!-- End Insert -->
The only problem is with the delete system, if I delete a row then, another row within another user is also being deleted. Is there any other way to delete messages but only for the user.