Jump to content

Simple Email Client


YehWoopDeLoop

Recommended Posts

Hi

 

This is for a simple email client.

 

I am trying to create a delete button that deletes a message when in message view from the MySQL database. Bellow is what I have so far. Currently it sends an alert confirming the message has been deleted and goes back to the inbox view where, it is evident that nothing has been deleted. Even when I log out then back in, the message is still there.

 

// This is how I call the JavaScript function in the html page:

<input type="button" value="Delete" onclick="deleteMessage();" />

// This is the relevant JavaScript:

/* ~~~~~~~~~~~~~~~~~~~~~~~~~~ Functions used to Delete a message ~~~~~~~~~~~~~~~~~~~~~~~~~~ */

var requestDlt = false;                                 // for the message to delete

/* I created my own addition PHP script that, if correct, should delete a message when in message view */

function deleteMessage(mailNumber) 
{
   var url =  "delete.php?mailID="+mailNumber;               // assign to the url                           
   if (window.ActiveXObject)                           // if the users window matches this
   {                                             // then
      requestDlt = new ActiveXObject("Microsoft.XMLHTTP");   // create a new ActiveXObject
   } else if (window.XMLHttpRequest)                     // else if the window matches this
   {                                             // then
      requestDlt = new XMLHttpRequest();                  // the global variable is an XMLHttpRequest
   }
   if (requestDlt!=null)                              // if the request exists 
   {
       requestDlt.onreadystatechange=RequestFunctionDelete;   // when ready envoke RequestFunctionMessage
        requestDlt.open("GET",url);                        // the request will now open the assigned url
      requestDlt.send(null);                           // send the request
   }
}

function RequestFunctionDelete()
{
   if (requestDlt.readyState==4)                        // if all has been sent
   {                                             // and
      if (requestDlt.status==200)                        // if it is all OK
      {   
      /* if in message view, hide it, and show inbox */
      if (document.getElementById("messageView").style.display!="none")
      {                                    
         var response=requestDlt.responseText;            // the variable response will hold the response text
              alert(response);                        // display the response to the user
            $("#messageView").fadeOut(1000, function()       // hide message
            {
                $("#inboxBox").fadeIn(1000);            // show inbox
            });   
         } else {                                 // else
            /*  Warn user they are unable to access button in this view */   
            alert("select a message you would like to delete");            
         }
      } 
   } 
}

// And lastly, here is the PHP Script that is called:

<?php
header('Content-Type: text/xml');
header("Cache-Control: no-cache, must-revalidate");
$dbhost = 'localhost';
$dbuser = 'cjc16';
$dbpass = 'cjc16';
$dbname = 'cjc16';
$dbtable = 'mail';


$id=$_GET["mailID"];


$con = mysql_connect($dbhost, $dbuser, $dbpass);
if (!$con)
{
    die('Could not connect: ' . mysql_error());
}

$dbselect = mysql_select_db($dbname,$con);

$sql="DELETE FROM $dbtable WHERE mailID='$id'";

$result = mysql_query($sql);

if ($result) {
        echo "Deleted";    
} else {  
    echo 'Unable to  delete';  
} 

mysql_close($con);

?>

 

Mod edit:

 . . . 

tags added.

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.