Jump to content

When message is recieved by recipient, Message dissapears from senders inbox


Recommended Posts

Hi, When a user sends a message toa nother user' a copy of the message is then sent to their sentbox until the recipient reads it, in which case it is then deleted; I know why this is i just need help in correcting the code so Im asking for some more experienced knowledge; thanks :) (im trying to understand the fundamentals by working on an existing script/tutorial btw)

 

<?php
session_start();
$user = $_SESSION['kt_login_id'];

   //Are they logged in or not?
if(!$user)
{
echo "<br><p>Blah blah you arent logged in and stuff, you should do that or something</p><br>";
}

else
{
//Get your private message count
//Find the percentage that your inbox is full
$sql = mysql_query ("SELECT pm_count FROM members WHERE member_id='$user'");
$row = mysql_fetch_array ($sql);
$pm_count = $row['pm_count'];

$percent = $pm_count/'50';
$percent = $percent * '100';
?>

      <p class="profilehdr">Mail Center<br />Sentbox<br />
      
       <?php
 //Get all message that are sent by the logged in user, and that have the recieved field set to zero, meaning they have not been recieved, once read the view message page sets the recieved field for the message to 1
        $query = "SELECT * FROM messages_test WHERE sender='$user' AND recieved='0'";
        $sqlinbox = mysql_query($query);
        
        //If there is a MySQL error we need to display the error because something has gone horribly wrong on the server.
        if(!$sqlinbox)
            {
            ?>
            <p><?php print '$query: '.$query.mysql_error();?></p>
            <?php
            }
        
        //If all messages sent by the user were recieved or deleted, then jsut say that there are no messages not recieved  
        elseif (!mysql_num_rows($sqlinbox) )
            {
            ?>
            <p><b>You have no un-recieved messages to display</b></p>
            
            
	<?php
	}

//There are no rows found for the user that is logged in, so I guess that means they dont have any messages or maybe its all broken  
elseif (!mysql_num_rows($sqlinbox) )
	{
	?>
      <center>
<p class="profilehdr"><b>You have no messages to display</b>
	  <?php
	}

//So if there is not an error, and they apparently do have messages we need to get their information and display it.
else
	{
	//Ok, Lets center this whole table Im going to make just because I like it like that
	//Then we create a table 80% the total width with 3 columns The subject is 75% of the whole table, the sender is 120 pixels (should be plenty) and the select checkboxes only get 25 pixels
	?>

	  <form name="send" method="post" action="delete.php">
	</p>
	<table width="100%">
	<tr valign="middle">
	  <td width="4%" class="message_header">Check</td>
	  <td width="16%" class="message_header">Date</td>
	  <td width="145px" class="message_header">To</td>  
	  <td width="9%" class="message_header">Status</td>
	  <td width="145px" class="message_header">Subject</td>
	  		</tr>
	<?php
	//Ok cool, now we stick it all into an array and we will dispaly it now
	while($inbox = mysql_fetch_array($sqlinbox))
		{
		//These are the variables we have the id of the private message, we have the person who sent the message, we have the subject of the message, and yeah thats it
		$pm_id = $inbox['id'];
		$reciever = $inbox['reciever'];
		$subject = $inbox['subject'];
		$datetime = $inbox['datetime'];
		$replied = $inbox['replied'];


		?>
		<tr valign="middle">
		  <td width="4%" align="center" class="message_rows"><input name="pms[]" type="checkbox" value="<?php echo $pm_id; ?>" /></td>
		  <td width="16%" align="left" class="message_rows"><?php echo $datetime; ?></td>
		  <td class="message_rows"><?php echo $reciever; ?></td>
		  <td width="9%" class="message_rows"><?php echo $replied; ?></td>
		  <td class="message_rows"><a href="mail_viewmsg.php?msg_id=<?php echo $pm_id; ?>" class="message_rows_subject"><?php echo $subject; ?></a></td>
      </tr>
		<?php
		//This ends the while loop
		}
	?>
	<tr>  
	<td height="10" colspan="7"></td>
	</tr>
	<tr valign="middle">
	  <td colspan="7"><table class="footerCell" width="100%" cellpadding="0" cellspacing="0">
              <tr>
                <th align="left" valign="middle" bgcolor="#6698CB" style="padding-left:8px"></th>
                <th colspan="3" align="right" bgcolor="#6698CB"> <input name="Submit" type="submit" value="Delete Selected" />                </th>
            </tr>
            </table></td>
	  </tr>
	</table>
<?php
	//So this ends the else to see if it is all ok and having messages or not
	}

//This ends that first thing that checks if you are logged in or not
}
?> 

 

is my code at the moment, I understand this section is causing my problem, or so i think it is; only how do i go about removing it? where would i start deleting from ? thanks again  :)

   //If all messages sent by the user were recieved or deleted, then jsut say that there are no messages not recieved  
        elseif (!mysql_num_rows($sqlinbox) )
            {
            ?>
            <p><b>You have no un-recieved messages to display</b></p>
            
            
	<?php
	}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.