Thanks for joining the conversation dagon
k i took out the header in the loop. that totally makes sense 🙂
added Int and sent_id in the query
right now with this code it doesnt delete anything
<?php
if(isset($_POST['delete'])) {
foreach ($_POST['association'] as $sent_id){
mysql_query('DELETE FROM `sent` WHERE `sent_id`= ' . (int) $sent_id);
}
header("Location: sent.php?sent=1");
went ahead and just posted the code on my page. I really need some help on this been struggling on it for days and reading lots of tutors and examples online.
} ?>
<?php
// Date in the past
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache");
header("Pragma: no-cache");
?>
<? require("menu.php"); ?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="sitestyle.css" />
<style type="text/css">
.containera
{
position:relative;
width:100%;
}
.menu
{
position:absolute;
left:160px;
width:300px;
background-color:transparent;
}
.deletecontainer
{
position:relative;
width:100%;
}
.delete
{
position:absolute;
left:65px;
width:300px;
background-color:transparent;
}
</style>
<script type="text/javascript">
function checkUncheckAll(groupName, checkState){
var groupObj = document.forms[0].elements[groupName];
var groupLen = groupObj.length;
for(var groupIdx=0; groupIdx<groupLen; groupIdx++)
{
groupObj[groupIdx].checked = checkState;
}
return;
}
</script>
</head>
<body>
<div class="containera">
<div class="menu">
<table width="88%" height="0" border="0" cellspacing="0">
<tr>
<td height="0" align="center"><a href="inbox.php?inbox=1">Inbox</a>
</td> <td height="0" align="center"><a href="compose.php">Compose</a></td>
<td height="0" align="center"><a href="sent.php?sent=1">Sent</a></td>
<td height="0" align="center"><a href="trash.php">Trash</a></td>
</tr>
<tr>
</table>
</div>
</div>
<br/ >
<br/ >
<form name="frm1" id="frm1" action="" method="post"
15.onsubmit="javascript:return submitIt('frm1')">
<p>
<center>
<table width="60%" border="1" cellspacing="1" cellpadding="0">
<tr align="center">
</tr>
<tr align="center">
<td><input type="checkbox" name="checkAll" value="x" id="checkall" onclick="checkUncheckAll('association[]', this.checked)" /></td>
<td>Recipient</td>
<td>Subject</td>
<td>Sent</td>
<td>read/unread</td>
</tr>
<?php
// find out how many rows are in the table
$count3 = "SELECT COUNT(*) FROM sent WHERE id = '".($_SESSION['user_id'])."'";;
$count2 = mysql_query($count3) or trigger_error("SQL", E_USER_ERROR);
$r = mysql_fetch_row($count2);
$numrows = $r[0];
// number of rows to show per page
$rowsperpage = 10;
// find out total pages
$totalpages = ceil($numrows / $rowsperpage);
// get the current page or set a default
if (isset($_GET['sent']) && is_numeric($_GET['sent'])) {
// cast var as int
$currentpage = (int) $_GET['sent'];
} else {
// default page num
$currentpage = 1;
}// end if
// if current page is greater than total pages...
if ($currentpage > $totalpages) {
// set current page to last page
$currentpage = $totalpages;
}// end if
// if current page is less than first page...
if ($currentpage < 1) {
// set current page to first page
$currentpage = 1;
} // end if
// the offset of the list, based on current page
$offset = ($currentpage - 1) * $rowsperpage;
// get the info from the db
$count3 = "SELECT * FROM sent WHERE id = '".($_SESSION['user_id'])."' ORDER BY time DESC LIMIT $offset, $rowsperpage ";
$count2 = mysql_query($count3) or trigger_error("SQL", E_USER_ERROR);
// while there are rows to be fetched...
while ($list = mysql_fetch_assoc($count2)) {
// these are variables to place in the echo
$sent_id = $list['sent_id'];
$recipient = $list['sendto'];
$subject = $list['subject'];
$read = $list['read'];
// grabs the time offset
$take3 = "SELECT time_offset FROM users WHERE id='".mysql_real_escape_string($_SESSION['user_id'])."'";
$take2 = mysql_query($take3) or die(mysql_error());
$take1 = mysql_fetch_array($take2);
$recieved = $list['time'];
// adds the users time offset to the inputed time
$time = ($recieved + $take1['time_offset']);
// sets default time to UTC then formats the inputed time that was offset with the users offset
date_default_timezone_set('UTC');
$user_offset = date('h:i:s a M/d', $time);
?>
<tr>
<td><center><input type="checkbox" name="association[]" value="<?php echo $sent_id[0];?>" id="1" /></center></td>
</label></td>
<td><center><a href="search_goaulds.php?goauld=<?php echo $recipient; ?>"><?php echo $recipient ?></a></center></td>
<td><center><a href="sent_view.php?sent_id=<?php echo $sent_id; ?>"><?php echo $subject ?></a></center></td>
<td><center><?php echo $read ?></center></td>
<td><center><?php echo $user_offset ?></center></td>
</tr>
<?php } // while loop
?>
</table>
</center>
<div class="deletecontainer">
<div class="delete">
<br/>
<input type="submit" name="delete" id="delete" value="Delete"></p>
</form>
</div>
</div>
<?php
$check3 = "SELECT COUNT(*) FROM sent WHERE id='".mysql_real_escape_string($_SESSION['user_id'])."'";
$check2 = mysql_query($check3) or die(mysql_error());
$check1 = mysql_fetch_row($check2);
$numrow = $check1[0];
// makes sure no pagination links are displayed when no messages exist
if($numrow < 1){
echo "<p><center><h2>You have not sent any messages</h2><center></p>";
}else{
// makes sure no pagination links are displayed when there are more 1 and less then 11 messages
if ($numrow >= 11){
/****** build the pagination links ******/
// if not on page 1, don't show back links
if ($currentpage > 1) {
// show << link to go back to page 1
echo " <a href='{$_SERVER['PHP_SELF']}?sent=1'><<</a> ";
// get previous page num
$prevpage = $currentpage - 1;
// show < link to go back to 1 page
echo " <a href='{$_SERVER['PHP_SELF']}?sent=$prevpage'>Previous</a> ";
}
// range of num links to show
$range = 3;
// loop to show links to range of pages around current page
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
// if it's a valid page number...
if (($x > 0) && ($x <= $totalpages)) {
// if we're on current page...
if ($x == $currentpage) {
// 'highlight' it but don't make a link
echo " [<b>$x</b>] ";
// if not current page...
} else {
// make it a link
echo " <a href='{$_SERVER['PHP_SELF']}?sent=$x'>$x</a> ";
}
}
}
// if not on last page, show forward and last page links
if ($currentpage != $totalpages) {
// get next page
$nextpage = $currentpage + 1;
// echo forward link for next page
echo " <a href='{$_SERVER['PHP_SELF']}?sent=$nextpage'>Next </a> ";
// echo forward link for lastpage
echo " <a href='{$_SERVER['PHP_SELF']}?sent=$totalpages'>>></a> ";
}
}
}
if(isset($_POST['delete'])) {
foreach ($_POST['association'] as $sent_id){
mysql_query('DELETE FROM `sent` WHERE `sent_id`= ' . (int) $sent_id);
}
header("Location: sent.php?sent=1");
}
?>
</body>
</html>