coolcam26 Posted November 21, 2010 Share Posted November 21, 2010 Here is my code so far... <head> <script type="text/javascript" src="includes/jquery.js"></script> <script language="javascript" type="text/javascript"> $(document).ready(function(){ //trigger when clicking element $(".toggle").click(function () { //check visibility if ($(this).next().is(":hidden")) { $(this).next().slideDown("slow"); //slide it down } else { $(this).next().hide(); //hide it } }); }); </script> </head> <?php include("header.inc"); ?> <table border="0" width="100%"><tr><td valign="top" width="800"> <?php echo "<div id='content'>"; echo "<h2 div id='title'>"; echo "Messages"; echo "</h2>"; if($_SESSION['uid']){ echo "<div align='right'><a href='create_message.php'>Create Message  </a></div>"; echo "<h3 div id='subtitle'>"; echo "Inbox"; echo "</h3>"; //Inbox/////////////////////////////////////////////////////////////// $query = mysql_query("SELECT * FROM messages WHERE to_user='$username' ORDER BY id DESC"); $numrows = mysql_num_rows($query); if ($numrows != 0){ echo "<form action='delete_message.php' method='POST'>"; echo "<div id='messages'> <div id='leftside'>From...</div> <div id='leftside'><input type='submit' name='deleteinbox' value='Delete' class='button'></div> <div id='rightside'>Date</div> <div id='center'>Subject and Message</div> <div style='clear: both;'></div> </div>"; while($row = mysql_fetch_assoc($query)){ $msg_id = $row['id']; $msg_to_user = $row['to_user']; $msg_to_id = $row['to_id']; $msg_from_user = $row['from_user']; $msg_from_id = $row['from_id']; $msg_subject = $row['subject']; $msg_content = $row['content']; $msg_date = $row['date']; $msg_from_delete = $row['from_delete']; $msg_to_delete = $row['to_delete']; if (!$msg_to_delete){ echo "<div id='messages'>"; echo "<div id='leftside'> <input type='checkbox' name='cb$msg_id' value='$msg_id'> <a href='profile.php?id=$msg_from_id' target='_blank'>$msg_from_user</a> </div>"; echo "<div id='rightside'>$msg_date</div>"; echo "<div id='center'> <span class='toggle'><a href='#'>$msg_subject</a></span> <div class='hiddenDiv'> <br>$msg_content<br><br> <span class='toggle'><a href='#'>REPLY</a></span> <div class='hiddenDiv'> <form action='msgreply.php' method='POST'> <input type='hidden' value='$msg_id' name='replyid'> <input type='text' name='replysubject' style='width: 300px;' class='text-box' value='RE: $msg_subject'><br> <textarea name='replycontent' style='width: 298px;' rows='5'></textarea><br><br> <input type='submit' name='replybutton' class='button' value='Reply'> </form> </div> </div> </div>"; echo "<div style='clear: both;'></div>"; echo "</div>"; $num += 1; } } if ($num == 0){ echo "You have no messages in your inbox."; } echo "</form>"; } else echo "You have no messages in your inbox!"; }else echo "You must be logged in to view your messages!"; ?> </div> </td><td width="250"> <?php include("sidebar.inc"); ?> </td> </table> </body> </html> <?php include("footer.inc"); ?> Basically I am making a personal messaging system however I can't seem to find a way of putting the reply form "inside" the delete form. Is there any simple answer as I am very new to php. The deletion works fine however whenever I submit a reply it takes me to the delete page! Thanks, Cameron Quote Link to comment Share on other sites More sharing options...
requinix Posted November 21, 2010 Share Posted November 21, 2010 You can't have a inside another . It isn't allowed and doesn't work. HTML 5 has a workaround but until it gets implemented in the popular browsers you can't really use it. Use two separate forms. Quote Link to comment Share on other sites More sharing options...
coolcam26 Posted November 21, 2010 Author Share Posted November 21, 2010 So what other method could I use to enable replys and deletes on the same page? Quote Link to comment Share on other sites More sharing options...
ignace Posted November 21, 2010 Share Posted November 21, 2010 <input type="submit" name="action" value="Preview"> <input type="submit" name="action" value="Save"> <input type="submit" name="action" value="Delete Post"> <?php echo $_POST['action']; // Preview, or Save, or Delete Post ?> Not sure if this works cross-browser. Quote Link to comment Share on other sites More sharing options...
coolcam26 Posted November 22, 2010 Author Share Posted November 22, 2010 Sorry but err... I know this probably sounds really stupid but how do I use it? Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 22, 2010 Share Posted November 22, 2010 What Ignace is suggesting is using different submit buttons for the action to be taken. The problem with this approach is that pressing enter will submit a form and there will be no submit value to check on the receiving page. However, the only time you would even consider that is if you were using the same form fields for different operations. I can't believe you would be using the same form fields for a "reply" and a "delete". So the solution is as requinix suggested and have two separate forms. One form must be closed before you start another. <form name="reply"> // reply form goes here </form> <form name="delete"> // delete form goes here </form> Quote Link to comment Share on other sites More sharing options...
coolcam26 Posted November 22, 2010 Author Share Posted November 22, 2010 I'm not sure if this will work as the reply form is inside a loop inside the delete form! Quote Link to comment Share on other sites More sharing options...
coolcam26 Posted November 23, 2010 Author Share Posted November 23, 2010 I'm not sure if this will work as the reply form is inside a loop inside the delete form! Are you sure this will work? Quote Link to comment Share on other sites More sharing options...
litebearer Posted November 23, 2010 Share Posted November 23, 2010 did you try it? - the key to learning is to EXPERIMENT!! Quote Link to comment Share on other sites More sharing options...
coolcam26 Posted November 23, 2010 Author Share Posted November 23, 2010 As you can probably tell already I am not very good with php and I also get confused will all the elses and ifs! This is the error message that I got: Parse error: syntax error, unexpected T_ELSEIF in /****/********/public_html/deleteorsend.php on line 46 The code I used for it was: <?php include("header.inc"); ?> <table border="0" width="100%"><tr><td valign="top" width="800"> <div id="content"> <?php //Start Content if($_SESSION['uid']){ $replybtn = $_POST['replybutton']; $inboxbtn = $_POST['deleteinbox']; $outboxbtn = $_POST['deleteoutbox']; if ($replybtn){ $subject = $_POST['replysubject']; $content = $_POST['replycontent']; $replyid = $_POST['replyid']; if ($subject && $content){ $date = date("M d, Y"); $query = mysql_query("SELECT * FROM messages WHERE content='$content' AND date='$date'"); $numrows = mysql_num_rows($query); if ($numrows == 0){ $query = mysql_query("SELECT * FROM messages WHERE id='$replyid' AND to_user='$username'"); $numrows = mysql_num_rows($query); if ($numrows == 1){ $row = mysql_fetch_assoc($query); $to_id = $row['from_id']; $to_user = $row['from_user']; mysql_query("INSERT INTO messages VALUES ('', '$to_user', '$to_id', '$username', '$userid', '$subject', '$content', '$date', '0', '0')"); echo "Your reply has been sent. <a href='messages.php'>Click here</a> to return to your inbox."; } else echo "No message was sent. An error has occured!!!!"; } else echo "You can NOT resend the same messages."; } else echo "You did not supply a subject and/or message."; } else{ echo "You must submit a response to a message."; } elseif ($inboxbtn){ $query = mysql_query("SELECT * FROM messages WHERE to_user='$username'"); while ($row = mysql_fetch_assoc($query)){ $msg_id = $row['id']; $value = "cb"."$msg_id"; $checkbox = $_POST[$value]; if ($checkbox){ mysql_query("UPDATE messages SET to_delete='1' WHERE id='$msg_id'"); } } echo "The selected messages have been deleted! <a href='messages.php'>Click here</a> to return to your inbox."; } elseif ($outboxbtn){ $query = mysql_query("SELECT * FROM messages WHERE from_user='$username'"); while ($row = mysql_fetch_assoc($query)){ $msg_id = $row['id']; $value = "cb"."$msg_id"; $checkbox = $_POST[$value]; if ($checkbox){ mysql_query("UPDATE messages SET from_delete='1' WHERE id='$msg_id'"); } } echo "The selected messages have been deleted! <a href='messages.php'>Click here</a> to return to your inbox."; } else echo "You must click the button!"; } else echo "You must be logged in to do that!"; //End Content ?> </div> </td><td width="250"> <?php include("sidebar.inc"); ?> </td> </table> <?php include("footer.inc"); ?> </div> </div> Is that the sort of thing you were suggesting, I'm not really sure!! Quote Link to comment Share on other sites More sharing options...
coolcam26 Posted November 23, 2010 Author Share Posted November 23, 2010 Any ideas? Sorry if I sound a bit unpacient but I'm the sort of person who likes to get one thing finished before I move on to the next!! Quote Link to comment 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.
× 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.