Jump to content

Private messaging help


unknown1

Recommended Posts

I have created a private message system but from some reason it's seems to post

composed messages twice... The error is in the following code but can't see why it would be posting twice. Can someone please have a look and possibly help me figure out why.

 

Thanks in advance!!

 

<? case 'compose':

if(!$_POST[send]){?>
<div id="main_heading_text" class="left">My Inbox: Compose Message</div>
  <div id="main_list_buttons" class="right"></div>
    <div class="my_account_info" id="contentdiv" >
<form method="post" action="">

<table width="680" border="0" cellspacing="0" cellpadding="0" style='border: 1px solid #E1F4A6; '>
  <tr>
    <td width="212" height="35" bgcolor="#E7F7A5"><br  />
      <span class="edit_profile_label" style="padding-left:8px;">User Name:</span>      <?  if(isset($_GET[user])){ //check if there is a user in the address bar
echo "<input type='text' name='to' value='$_GET[user]' size='15'>"; //if there is






}else{ //or not..
echo "<input type=\"text\" name=\"to\" size=\"15\">"; //echo the input box without the value of the user!
} //end user check in address bar</b>?></td>
    <td width="466" height="50" bgcolor="#E7F7A5" ><br  /><b class="edit_profile_label" > Subject:</b><input type="text" name="title" value="My Offer" size="15"></td>
  </tr>
  <tr>
    <td height="125" colspan="2" valign="top" style="padding-left:8px;"><p> </p>
      <p> </p>
      <p><b class="edit_profile_label" style="font-size:14px;">Message:</b><br /><br />
        <textarea name="message" rows="6" cols="75"></textarea>
        <br /><br /><br /><br />
      </p></td>
  </tr>
  <tr>
    <td height="35" style="padding-left:8px;"><input type="submit" name="send" value="Send message" id="update_listing_btn" ><br  /><br  /></td>
    <td><a href="my_account.php?page=pm" style="font-size:12px; color:#00AEBF;">Back to inbox</a></td>
  </tr>
  <tr>
    <td height="35" bgcolor="#E7F7A5"> </td>
    <td bgcolor="#E7F7A5"> </td>
  </tr>
</table>
</form>
<? }else{ //or if it was....
$to = stripslashes(htmlspecialchars(strip_tags($_POST[to]))); //who its to
$from =$_SESSION[uSERNAME]; //who its from
$date = date("F j, Y, g:i a"); //the date sent
$msg = addslashes($_POST[message]); //the message variable
$subject = addslashes($_POST[title]); //the subject
$do = mysql_query("INSERT INTO `private_msg` (`to`,`from`,`date`,`subject`,`content`) VALUES ('" . $to . "','" . $from . "','" . $date . "','" . $subject . "','" . $msg . "')") or die(mysql_error()); //insert into the table!
echo "<div id='main_heading_text' class='left'>My Inbox: Compose Message</div>
  <div id='main_list_buttons' class='right'></div>
    <div class='my_account_info' id='contentdiv' >
<table width='680' border='0' cellspacing='0' cellpadding='0' style='border: 1px solid #E1F4A6; '>
  <tr>
    <td  height='35' bgcolor='#E7F7A5'></td></tr>
    <tr><td><br /><br /><center>Message Sent!   <a href=\"my_account.php?page=pm\" style=\"font-size:12px; color:#00AEBF; \">Go back to inbox</a></center><br /><br /></td></tr>
    <tr>
    <td height='35' bgcolor='#E7F7A5'></td></tr>
    </table>";?>
<?}?>

<? break; ?>

Link to comment
Share on other sites

"post composed message twice..." What?

It displays twice in the view screen or gets placed in the database twice?

And, is it just the message that is duplicated or is all of the detail repeated such as to, from, time, date, message, etc...

 

Answering these questions will make in more likely that someone can help you.

 

Handy PHP

Link to comment
Share on other sites

The other code is case view.

I still can't see why it would submit to the database twice... the only thing I can see that maybe

the issue is the reply and send conditions but the conditions are different on reply and send so I'm not sure how.

 

<? case 'view':
$id = (int)htmlspecialchars(strip_tags($_GET[id]));
$msgs = mysql_query("SELECT * FROM `private_msg` WHERE `to` = '" . $_SESSION[uSERNAME] . "' ORDER BY `pid` ASC")
or die(mysql_error()); //get all the messages to the loged in user 
$id = (int)htmlspecialchars(strip_tags($_GET[id]));  //make the ID safe
if(!$id){ 
$user_message = "<table width=\"680\" border=\"0\" align=\"left\" cellpadding=\"5\" cellspacing=\"0\" class='private_msg_tbl' ><tr class=\"edit_profile_label\">
<td width=\"680\" height=\"35\" bgcolor=\"#E7F7A5\"> </td>
<td width=\"680\" ><a href=\"pm.php\">Go back to inbox</a> <br /><br />No ID Selected!</td>
<td width=\"680\" height=\"35\" bgcolor=\"#E7F7A5\"> </td></tr> </table>";
?>
<? }else{
$select = mysql_query("SELECT * FROM `private_msg` WHERE `pid` = '" . $id . "';"); //get the message's info
$msg = mysql_fetch_array($select); //select all data
if($msg[to] != $_SESSION[uSERNAME]){ //check if the user logged
$user_message= "<table width=\"680\" border=\"0\" align=\"left\" cellpadding=\"5\" cellspacing=\"0\" class='private_msg_tbl'><tr class=\"edit_profile_label\">
<td width=\"680\" height=\"35\" bgcolor=\"#E7F7A5\"> </td>
<td width=\"680\" ><a href=\"pm.php\">Go back to inbox</a><br /><br />This Message Was Not Sent To You</td>
<td width=\"680\" height=\"35\" bgcolor=\"#E7F7A5\"> </td></tr> </table>"; 
}else{ //maybe...
if(!$_POST[reply]) { //if the reply was not submitted
$mark = mysql_query("UPDATE `private_msg` SET `status` = 'Read' WHERE `pid` = '" . $id . "'") or die(mysql_error()); //mark it as Read
$message = nl2br(stripslashes($msg[content])); //make new lines to  and strip the slashes
$subject = stripslashes($msg[subject]);  //strip the slashes

$user_message="<table width=\"680\" align=\"left\" cellpadding=\"5\" cellspacing=\"0\" style='border: 1px solid #E1F4A6; ' ><form method=\"post\">
<tr  >
    <td width='153' height='35' bgcolor='#E7F7A5' style='padding-left:7px;'><b class='edit_profile_label'>Subject:</b> $subject</td>
    <td width='507' bgcolor='#E7F7A5' style='padding-left:7px;' ><b class='edit_profile_label'>From:</b> $msg[from]</td>
  </tr>
  <div id='div_spacer'>
  <tr >
    <td height='100' colspan='2' style='padding-left:12px;'>$message</td>
    </tr>
  <tr>
    <td height='80' colspan='2' style='padding-left:8px;'><textarea rows=\"6\" cols=\"45\" name=\"msg\" ></textarea></td>
    </tr>
  <tr>
    <td height='35' style='padding-left:8px;'><input type=\"submit\" name=\"reply\" value=\"Reply\"  style='
border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none;
width: 75px; font-weight: normal; color: #FFF; text-decoration: none; background-color: #00AEBF;
height: 23px; float: left;'>  </td>
    <td><a href=\"my_account.php?page=pm\" style=\"font-size:12px; color:#00AEBF; \">Go back to inbox</a></td>
  </tr>
  <tr>
    <td height='35' bgcolor='#E7F7A5'> </td>
    <td bgcolor='#E7F7A5'> </td>
  </tr> </table></form></div>
";
}else{
$to = $msg[from]; //get who it is to
$from =$_SESSION[uSERNAME]; //who its from
$subject = "RE: " . $msg[subject]; //new subject
$msg = addslashes($_POST[msg]); //the content
$date = date("F j, Y, g:i a"); //the date sent
$do = mysql_query("INSERT INTO `private_msg` (`to`,`from`,`date`,`subject`,`content`) VALUES ('" . $to . "','" . $from . "','" . $date . "','" . $subject . "','" . $msg . "')") or die(mysql_error()); //insert into the table!

$user_message="<table width=\"680\" border=\"0\" align=\"left\" cellpadding=\"5\" cellspacing=\"0\" class='private_msg_tbl' ><tr class=\"edit_profile_label\">
<td width=\"680\" height=\"35\" bgcolor=\"#E7F7A5\"> </td><tr>
<td width=\"680\" >Message Sent!</td></tr>
<td width=\"680\" height=\"35\" bgcolor=\"#E7F7A5\"> </td></tr> </table>";

echo "$user_message";

}
}
}

?>

Link to comment
Share on other sites

why are you updating a clue?

 

look loook looook you got eyes i am blind and see the problem?

 

and got a weight stick it all true.....

 

my god the worse way off using switch in the world correct it please.....

 

what this in all your code.

 

$_POST[reply] <<<< not $_POST['reply'] any reason?

Link to comment
Share on other sites

why are you updating a clue?

 

look loook looook you got eyes i am blind and see the problem?

 

and got a weight stick it all true.....

 

my god the worse way off using switch in the world correct it please.....

 

Very helpful. Smart ass!

 

Anyways, I'm sure I will have to rewrite the code before anyone give me a str8 answer.

 

Thanks!

Link to comment
Share on other sites

Not sure if this will help but

 

<? case 'compose':

if(!$_POST[send]){?>

 

 

<div id="main_heading_text" class="left">My Inbox: Compose Message</div>
     <div id="main_list_buttons" class="right"></div>
    <div class="my_account_info" id="contentdiv" >
<form method="post" action="">

<table width="680" border="0" cellspacing="0" cellpadding="0" style='border: 1px solid #E1F4A6; '>
  <tr>
    <td width="212" height="35" bgcolor="#E7F7A5"><br  />
      <span class="edit_profile_label" style="padding-left:8px;">User Name:</span>

 

<?  if(isset($_GET[user])){ //check if there is a user in the address bar
echo "<input type='text' name='to' value='$_GET[user]' size='15'>"; //if there is
}else{ //or not..
echo "<input type=\"text\" name=\"to\" size=\"15\">"; //echo the input box without the value of the user!
} //end user check in address bar</b>?>

 

 

</td>
    <td width="466" height="50" bgcolor="#E7F7A5" ><br  /><b class="edit_profile_label" > Subject:</b><input type="text" name="title" value="My Offer" size="15"></td>
  </tr>
  <tr>
    <td height="125" colspan="2" valign="top" style="padding-left:8px;"><p> </p>
      <p> </p>
      <p><b class="edit_profile_label" style="font-size:14px;">Message:</b><br /><br />
        <textarea name="message" rows="6" cols="75"></textarea>
        <br /><br /><br /><br />
      </p></td>
  </tr>
  <tr>
    <td height="35" style="padding-left:8px;"><input type="submit" name="send" value="Send message" id="update_listing_btn" ><br  /><br  /></td>
    <td><a href="my_account.php?page=pm" style="font-size:12px; color:#00AEBF;">Back to inbox</a></td>
  </tr>
  <tr>
    <td height="35" bgcolor="#E7F7A5"> </td>
    <td bgcolor="#E7F7A5"> </td>
  </tr>
</table>
</form>

 

 

<? }else{ //or if it was....
$to = stripslashes(htmlspecialchars(strip_tags($_POST[to]))); //who its to
$from =$_SESSION[uSERNAME]; //who its from
$date = date("F j, Y, g:i a"); //the date sent
$msg = addslashes($_POST[message]); //the message variable
$subject = addslashes($_POST[title]); //the subject
$do = mysql_query("INSERT INTO `private_msg` (`to`,`from`,`date`,`subject`,`content`) VALUES ('" . $to . "','" . $from . "','" . $date . "','" . $subject . "','" . $msg . "')") or die(mysql_error()); //insert into the table!
echo "<div id='main_heading_text' class='left'>My Inbox: Compose Message</div>
     <div id='main_list_buttons' class='right'></div>
    <div class='my_account_info' id='contentdiv' >
<table width='680' border='0' cellspacing='0' cellpadding='0' style='border: 1px solid #E1F4A6; '>
  <tr>
    <td  height='35' bgcolor='#E7F7A5'></td></tr>
    <tr><td><br /><br /><center>Message Sent!   <a href=\"my_account.php?page=pm\" style=\"font-size:12px; color:#00AEBF; \">Go back to inbox</a></center><br /><br /></td></tr>
    <tr>
    <td height='35' bgcolor='#E7F7A5'></td></tr>
    </table>";?>
<?}?>

<? break; ?>

 

 

 

<? case 'view':
$id = (int)htmlspecialchars(strip_tags($_GET[id]));
$msgs = mysql_query("SELECT * FROM `private_msg` WHERE `to` = '" . $_SESSION[uSERNAME] . "' ORDER BY `pid` ASC")
or die(mysql_error()); //get all the messages to the loged in user
$id = (int)htmlspecialchars(strip_tags($_GET[id]));  //make the ID safe
if(!$id){
$user_message = "<table width=\"680\" border=\"0\" align=\"left\" cellpadding=\"5\" cellspacing=\"0\" class='private_msg_tbl' ><tr class=\"edit_profile_label\">
<td width=\"680\" height=\"35\" bgcolor=\"#E7F7A5\"> </td>
<td width=\"680\" ><a href=\"pm.php\">Go back to inbox</a> <br /><br />No ID Selected!</td>
<td width=\"680\" height=\"35\" bgcolor=\"#E7F7A5\"> </td></tr> </table>";
}else{
$select = mysql_query("SELECT * FROM `private_msg` WHERE `pid` = '" . $id . "';"); //get the message's info
$msg = mysql_fetch_array($select); //select all data
if($msg[to] != $_SESSION[uSERNAME]){ //check if the user logged
$user_message= "<table width=\"680\" border=\"0\" align=\"left\" cellpadding=\"5\" cellspacing=\"0\" class='private_msg_tbl'><tr class=\"edit_profile_label\">
<td width=\"680\" height=\"35\" bgcolor=\"#E7F7A5\"> </td>
<td width=\"680\" ><a href=\"pm.php\">Go back to inbox</a><br /><br />This Message Was Not Sent To You</td>
<td width=\"680\" height=\"35\" bgcolor=\"#E7F7A5\"> </td></tr> </table>";
}else{ //maybe...
if(!$_POST[reply]) { //if the reply was not submitted
$mark = mysql_query("UPDATE `private_msg` SET `status` = 'Read' WHERE `pid` = '" . $id . "'") or die(mysql_error()); //mark it as Read
$message = nl2br(stripslashes($msg[content])); //make new lines to  and strip the slashes
$subject = stripslashes($msg[subject]);  //strip the slashes

$user_message="<table width=\"680\" align=\"left\" cellpadding=\"5\" cellspacing=\"0\" style='border: 1px solid #E1F4A6; ' ><form method=\"post\">
<tr  >
    <td width='153' height='35' bgcolor='#E7F7A5' style='padding-left:7px;'><b class='edit_profile_label'>Subject:</b> $subject</td>
    <td width='507' bgcolor='#E7F7A5' style='padding-left:7px;' ><b class='edit_profile_label'>From:</b> $msg[from]</td>
  </tr>
  <div id='div_spacer'>
  <tr >
    <td height='100' colspan='2' style='padding-left:12px;'>$message</td>
    </tr>
  <tr>
    <td height='80' colspan='2' style='padding-left:8px;'><textarea rows=\"6\" cols=\"45\" name=\"msg\" ></textarea></td>
    </tr>
  <tr>
    <td height='35' style='padding-left:8px;'><input type=\"submit\" name=\"reply\" value=\"Reply\"  style='
   border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none;
   width: 75px; font-weight: normal; color: #FFF; text-decoration: none; background-color: #00AEBF;
   height: 23px; float: left;'>  </td>
    <td><a href=\"my_account.php?page=pm\" style=\"font-size:12px; color:#00AEBF; \">Go back to inbox</a></td>
  </tr>
  <tr>
    <td height='35' bgcolor='#E7F7A5'> </td>
    <td bgcolor='#E7F7A5'> </td>
  </tr> </table></form></div>
";
}else{
$to = $msg[from]; //get who it is to
$from =$_SESSION[uSERNAME]; //who its from
$subject = "RE: " . $msg[subject]; //new subject
$msg = addslashes($_POST[msg]); //the content
$date = date("F j, Y, g:i a"); //the date sent
$do = mysql_query("INSERT INTO `private_msg` (`to`,`from`,`date`,`subject`,`content`) VALUES ('" . $to . "','" . $from . "','" . $date . "','" . $subject . "','" . $msg . "')") or die(mysql_error()); //insert into the table!

$user_message="<table width=\"680\" border=\"0\" align=\"left\" cellpadding=\"5\" cellspacing=\"0\" class='private_msg_tbl' ><tr class=\"edit_profile_label\">
<td width=\"680\" height=\"35\" bgcolor=\"#E7F7A5\"> </td><tr>
<td width=\"680\" >Message Sent!</td></tr>
<td width=\"680\" height=\"35\" bgcolor=\"#E7F7A5\"> </td></tr> </table>";

echo "$user_message";

}
}
}

?>

Link to comment
Share on other sites

Well, this isn't the prettiest code I've ever seen but it functions more or less.

 

And we all learned somewhere and it usually was deep in messy code so there isn't any reason to be so hard on the guy.  He's just looking for help!

 

I made the code a little easier for ME to read and may have found the issue but this isn't my strongest subject.  Basically, I have a very hard time reading this style of coding (not just yours).

 

I believe the you have the "view" case before the "compose" case and here is why I think that...

Your "view" case doesn't have a break statement at the end which will allow your code to read the next case even if it doesn't match the variable.  So when you view the message, it re-submits the message.

 

Here is your code indented to make it easier to read:

<? case 'compose':

     if(!$_POST[send]){?>
          <div id="main_heading_text" class="left">My Inbox: Compose Message</div>
          <div id="main_list_buttons" class="right"></div>
          <div class="my_account_info" id="contentdiv" >
          <form method="post" action="">

          <table width="680" border="0" cellspacing="0" cellpadding="0" style='border: 1px solid #E1F4A6; '>
               <tr>
                    <td width="212" height="35" bgcolor="#E7F7A5"><br  />
                         <span class="edit_profile_label" style="padding-left:8px;">User Name:</span>
          <?  if(isset($_GET[user])){ //check if there is a user in the address bar
               echo "<input type='text' name='to' value='$_GET[user]' size='15'>"; //if there is

          }else{ //or not..
               echo "<input type=\"text\" name=\"to\" size=\"15\">"; //echo the input box without the value of the user!
          } //end user check in address bar</b>?></td>
                    <td width="466" height="50" bgcolor="#E7F7A5" ><br  /><b class="edit_profile_label" > Subject:</b><input type="text" name="title" value="My Offer" size="15"></td>
               </tr>
               <tr>
                    <td height="125" colspan="2" valign="top" style="padding-left:8px;"><p> </p>
                         <p> </p>
                         <p><b class="edit_profile_label" style="font-size:14px;">Message:</b><br /><br />
                         <textarea name="message" rows="6" cols="75"></textarea>
                         <br /><br /><br /><br />
                         </p>
                    </td>
               </tr>
               <tr>
                    <td height="35" style="padding-left:8px;"><input type="submit" name="send" value="Send message" id="update_listing_btn" ><br  /><br  /></td>
                    <td><a href="my_account.php?page=pm" style="font-size:12px; color:#00AEBF;">Back to inbox</a></td>
               </tr>
               <tr>
                    <td height="35" bgcolor="#E7F7A5"> </td>
                    <td bgcolor="#E7F7A5"> </td>
               </tr>
          </table>
          </form>
          
     <? }else{ //or if it was....
          $to = stripslashes(htmlspecialchars(strip_tags($_POST[to]))); //who its to
          $from =$_SESSION[uSERNAME]; //who its from
          $date = date("F j, Y, g:i a"); //the date sent
          $msg = addslashes($_POST[message]); //the message variable
          $subject = addslashes($_POST[title]); //the subject
          $do = mysql_query("INSERT INTO `private_msg` (`to`,`from`,`date`,`subject`,`content`) VALUES ('" . $to . "','" . $from . "','" . $date . "','" . $subject . "','" . $msg . "')") or die(mysql_error()); //insert into the table!
          echo "<div id='main_heading_text' class='left'>My Inbox: Compose Message</div>
          <div id='main_list_buttons' class='right'></div>
          <div class='my_account_info' id='contentdiv' >
          <table width='680' border='0' cellspacing='0' cellpadding='0' style='border: 1px solid #E1F4A6; '>
               <tr>
                    <td  height='35' bgcolor='#E7F7A5'></td></tr>
               <tr><td><br /><br /><center>Message Sent!   <a href=\"my_account.php?page=pm\" style=\"font-size:12px; color:#00AEBF; \">Go back to inbox</a></center><br /><br /></td></tr>
               <tr>
                    <td height='35' bgcolor='#E7F7A5'></td></tr>
          </table>";?>
     <?}?>
<? break; ?>

<? case 'view':

     $id = (int)htmlspecialchars(strip_tags($_GET[id]));
     $msgs = mysql_query("SELECT * FROM `private_msg` WHERE `to` = '" . $_SESSION[uSERNAME] . "' ORDER BY `pid` ASC")
          or die(mysql_error()); //get all the messages to the loged in user
     $id = (int)htmlspecialchars(strip_tags($_GET[id]));  //make the ID safe
     if(!$id){
          $user_message = "<table width=\"680\" border=\"0\" align=\"left\" cellpadding=\"5\" cellspacing=\"0\" class='private_msg_tbl' ><tr class=\"edit_profile_label\">
               <td width=\"680\" height=\"35\" bgcolor=\"#E7F7A5\"> </td>
               <td width=\"680\" ><a href=\"pm.php\">Go back to inbox</a> <br /><br />No ID Selected!</td>
                <td width=\"680\" height=\"35\" bgcolor=\"#E7F7A5\"> </td></tr> </table>";
     ?>
     <? }else{
          $select = mysql_query("SELECT * FROM `private_msg` WHERE `pid` = '" . $id . "';"); //get the message's info
          $msg = mysql_fetch_array($select); //select all data
          if($msg[to] != $_SESSION[uSERNAME]){ //check if the user logged
               $user_message= "<table width=\"680\" border=\"0\" align=\"left\" cellpadding=\"5\" cellspacing=\"0\" class='private_msg_tbl'><tr class=\"edit_profile_label\">
                    <td width=\"680\" height=\"35\" bgcolor=\"#E7F7A5\"> </td>
                    <td width=\"680\" ><a href=\"pm.php\">Go back to inbox</a><br /><br />This Message Was Not Sent To You</td>
                    <td width=\"680\" height=\"35\" bgcolor=\"#E7F7A5\"> </td></tr> </table>";
          }else{ //maybe...
               if(!$_POST[reply]) { //if the reply was not submitted
                    $mark = mysql_query("UPDATE `private_msg` SET `status` = 'Read' WHERE `pid` = '" . $id . "'") or die(mysql_error()); //mark it as Read
                    $message = nl2br(stripslashes($msg[content])); //make new lines to  and strip the slashes
                    $subject = stripslashes($msg[subject]);  //strip the slashes
                    $user_message="<table width=\"680\" align=\"left\" cellpadding=\"5\" cellspacing=\"0\" style='border: 1px solid #E1F4A6; ' ><form method=\"post\">
                         <tr  >
                              <td width='153' height='35' bgcolor='#E7F7A5' style='padding-left:7px;'><b class='edit_profile_label'>Subject:</b> $subject</td>
                              <td width='507' bgcolor='#E7F7A5' style='padding-left:7px;' ><b class='edit_profile_label'>From:</b> $msg[from]</td>
                         </tr>
                         <div id='div_spacer'>
                         <tr >
                              <td height='100' colspan='2' style='padding-left:12px;'>$message</td>
                         </tr>
                         <tr>
                              <td height='80' colspan='2' style='padding-left:8px;'><textarea rows=\"6\" cols=\"45\" name=\"msg\" ></textarea></td>
                         </tr>
                         <tr>
                              <td height='35' style='padding-left:8px;'><input type=\"submit\" name=\"reply\" value=\"Reply\"  style='
                                   border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none;
                                   width: 75px; font-weight: normal; color: #FFF; text-decoration: none; background-color: #00AEBF;
                                   height: 23px; float: left;'>  </td>
                              <td><a href=\"my_account.php?page=pm\" style=\"font-size:12px; color:#00AEBF; \">Go back to inbox</a></td>
                         </tr>
                         <tr>
                              <td height='35' bgcolor='#E7F7A5'> </td>
                              <td bgcolor='#E7F7A5'> </td>
                         </tr> </table></form></div>
                    ";
               }else{
                    $to = $msg[from]; //get who it is to
                    $from =$_SESSION[uSERNAME]; //who its from
                    $subject = "RE: " . $msg[subject]; //new subject
                    $msg = addslashes($_POST[msg]); //the content
                    $date = date("F j, Y, g:i a"); //the date sent
                    $do = mysql_query("INSERT INTO `private_msg` (`to`,`from`,`date`,`subject`,`content`) VALUES ('" . $to . "','" . $from . "','" . $date . "','" . $subject . "','" . $msg . "')") or die(mysql_error()); //insert into the table!
                    $user_message="<table width=\"680\" border=\"0\" align=\"left\" cellpadding=\"5\" cellspacing=\"0\" class='private_msg_tbl' ><tr class=\"edit_profile_label\">
                         <td width=\"680\" height=\"35\" bgcolor=\"#E7F7A5\"> </td><tr>
                         <td width=\"680\" >Message Sent!</td></tr>
                         <td width=\"680\" height=\"35\" bgcolor=\"#E7F7A5\"> </td></tr> </table>";

                    echo "$user_message";

               }
          }
     }

?>

The last line above needs a break before it no matter what order the cases are in your code unless you want the script to execute the additional cases.

 

Now, a few suggestions for coding better in the future:

  • As mentioned previously, use $_POST['field'] instead of $_POST[field].  It'll prevent problems in the future.
  • Indent you code to keep your code more readable.  Finding a missing curly bracket or quote is much easier this way.
  • Create functions for your code and call those functions in your switch instead of raw code.
  • Use <?php instead of <? as some servers don't like the short tags.

 

That should do you for a bit.

 

Hope this helps,

Handy PHP

Link to comment
Share on other sites

Thanks for the tips....

 

The view case does have a break at the end of it but also have more html before the break

and didn't want to include the html for no reason it would have just made it harder to read =)

so I actually just forgot to add it when I posted here.

 

I knew before I even posted that it would be kinda hard to read but thought I would post anyway in hopes that someone could spot the problem.

 

I may just have to rewrite the code... I just thought it would be something simple cause it does function ok it's just sending messages to the database twice.

 

 

 

 

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.