Hi guys, I have a table of messeges where listed from database. I have added a column (thanks to php freak forum) where users can delete msgs from the table, there are two pages, view messege page which lists the messeges and a delete function page (please see below)
All the connections are fine and pagination works perfectly, but when i press on delete it wont delete anything from the database.
I have worked around it abit but still not working. Could you please help me to see what i am doing wrong here? im sure mysql is fine, surely there is something wrong im doing in my php
many thanks and merry xmas in advance.
View Messeges page:
<?php
session_start();
include ("../global.php");
//welcome messaage
$username=$_SESSION['username'];
echo "$username";
$query=mysql_query("SELECT id FROM users WHERE username='$username'");
while($row = mysql_fetch_assoc($query))
{
$user_id = $row['id'];
echo $id;
}
//get pageinatio in each page
$per_page=5;
/*
if( intval($_GET['start']) < 1 ) {
$start = 0;
} else {
$start = (int) $_GET['start'];
}
*/
$start=$_GET['start'];
$record_count =mysql_num_rows(mysql_query("SELECT * FROM msg"));
$max_page=$record_count/$per_page;
if(!$start)
$start=0;
$result= mysql_query("SELECT * FROM msg LIMIT $start, $per_page");
while($row = mysql_fetch_assoc($result))
{
$title=$row['title'];
$id_rent=$row['id_msg'];
?>
<table>
<tr>
<td><? echo $id_msg; ?></td>
<td><? echo $title; ?></td>
<td><?php echo "<a href='delete-msg.php?msg={$row['id_msg']}'>" ?>Delete</a></td></tr>
</tr>
</table>
<?php
//while
}
$prev=$start - $per_page;
$next=$start + $per_page;
if(!($start<=0))
echo
"<a href='view-msgs?start=$prev'>Previous</a>";
if(!($start>=$record_count-$per_page))
echo
"<a href='view-msgs.php?start=$next'>Next</a>";
mysql_close();
?>
delete-msg.php DELETE function page:
<?php
include ("../global.php");
$id=$_GET['id_msg'];
$result=mysql_query("DELETE FROM msg WHERE id_msg='$id'");
if($result){
echo "Deleted Successfully";
echo "<BR>";
echo "<a href='view-msg.php'>Back to main page</a>";
}
else {
echo "ERROR";
}
// close connection
mysql_close();
?>