unknown1 Posted September 28, 2009 Share Posted September 28, 2009 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; ?> Quote Link to comment https://forums.phpfreaks.com/topic/175836-private-messaging-help/ Share on other sites More sharing options...
Handy PHP Posted September 28, 2009 Share Posted September 28, 2009 "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 Quote Link to comment https://forums.phpfreaks.com/topic/175836-private-messaging-help/#findComment-926639 Share on other sites More sharing options...
unknown1 Posted September 29, 2009 Author Share Posted September 29, 2009 Just sent to the database twice. Quote Link to comment https://forums.phpfreaks.com/topic/175836-private-messaging-help/#findComment-926692 Share on other sites More sharing options...
Handy PHP Posted September 29, 2009 Share Posted September 29, 2009 Well, it would help to see the rest of the code but I think that outside of your switch, you are running the query again somehow. Please post any other code you have that uses $do or "INSERT..." Handy PHP Quote Link to comment https://forums.phpfreaks.com/topic/175836-private-messaging-help/#findComment-926701 Share on other sites More sharing options...
unknown1 Posted September 29, 2009 Author Share Posted September 29, 2009 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"; } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/175836-private-messaging-help/#findComment-926735 Share on other sites More sharing options...
redarrow Posted September 29, 2009 Share Posted September 29, 2009 look at the coding of that code, my god, where the hell you learn to code like that, please don't say collage? <?php $redarrow['redarrow'];?>; Quote Link to comment https://forums.phpfreaks.com/topic/175836-private-messaging-help/#findComment-926747 Share on other sites More sharing options...
redarrow Posted September 29, 2009 Share Posted September 29, 2009 Is it going into the database twice or showing twice.......... looking at the code going dizzy Quote Link to comment https://forums.phpfreaks.com/topic/175836-private-messaging-help/#findComment-926754 Share on other sites More sharing options...
unknown1 Posted September 29, 2009 Author Share Posted September 29, 2009 rofl, indeed. I'm sure I could have wrote it better but that's not the issue here. I didn't know good clean code was a prerequisite in order to get help.... I have my reasons for writing it this way. Regards! Quote Link to comment https://forums.phpfreaks.com/topic/175836-private-messaging-help/#findComment-926755 Share on other sites More sharing options...
Alex Posted September 29, 2009 Share Posted September 29, 2009 Putting code that contains php between [ php ] tags rather than [ code ] is a better idea because the syntax highlighting makes it easier to read. Quote Link to comment https://forums.phpfreaks.com/topic/175836-private-messaging-help/#findComment-926757 Share on other sites More sharing options...
unknown1 Posted September 29, 2009 Author Share Posted September 29, 2009 Anyways, it's going to the database twice. Quote Link to comment https://forums.phpfreaks.com/topic/175836-private-messaging-help/#findComment-926758 Share on other sites More sharing options...
redarrow Posted September 29, 2009 Share Posted September 29, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/175836-private-messaging-help/#findComment-926760 Share on other sites More sharing options...
unknown1 Posted September 29, 2009 Author Share Posted September 29, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/175836-private-messaging-help/#findComment-926763 Share on other sites More sharing options...
mikesta707 Posted September 29, 2009 Share Posted September 29, 2009 can you put the php in php tags and leave out the HTML. its kind of hard to read? Quote Link to comment https://forums.phpfreaks.com/topic/175836-private-messaging-help/#findComment-926784 Share on other sites More sharing options...
unknown1 Posted September 29, 2009 Author Share Posted September 29, 2009 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"; } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/175836-private-messaging-help/#findComment-926798 Share on other sites More sharing options...
Handy PHP Posted September 29, 2009 Share Posted September 29, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/175836-private-messaging-help/#findComment-926799 Share on other sites More sharing options...
unknown1 Posted September 29, 2009 Author Share Posted September 29, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/175836-private-messaging-help/#findComment-926811 Share on other sites More sharing options...
.josh Posted September 30, 2009 Share Posted September 30, 2009 rofl, indeed. I'm sure I could have wrote it better but that's not the issue here. I didn't know good clean code was a prerequisite in order to get help.... I have my reasons for writing it this way. Regards! It's not, but it greatly increases your chances of actually getting said help. Quote Link to comment https://forums.phpfreaks.com/topic/175836-private-messaging-help/#findComment-927398 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.