943,708 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 1400
  • PHP RSS
Aug 5th, 2009
0

One form, two actions

Expand Post »
I'm working a very simple script for an email (messaging) between users. I have a form with two buttons that gives you the option to save message as a draft or just send it to the user.

Here are the two buttons on form:
html Syntax (Toggle Plain Text)
  1. <input type="submit" name="save" id="save" value="Save as Draft" />
  2. <input type="submit" name="send" id="send" value="Send" />
Here is how I'm trying to differentiate between form actions.
php Syntax (Toggle Plain Text)
  1. if(isset($_POST['save']) && trim($_POST["save"])!==''){
  2. mysql_query("UPDATE mailbox SET
  3. member_id='$_SESSION[user_id]',
  4. message='$message',
  5. draft='DRAFT',
  6. subject='$subject',
  7. date='$dsub'
  8. WHERE id='$draftid'");
  9. header('Location: mailbox.php');
  10.  
  11. }elseif(isset($_POST['send']) && trim($_POST["send"])!==''){
  12. $send="INSERT INTO mailbox SET
  13. member_id='$memid',
  14. user_name='$$_SESSION[user_name]',
  15. user_id='$_SESSION[user_id]',
  16. message='$message',
  17. inbox='NEW',
  18. subject='$subject',
  19. date='$dsub' " ;
  20. $save_result=mysql_query($save);
  21. header('Location: mailbox.php');
  22.  
  23. // update draft to sent
  24. mysql_query("UPDATE mailbox SET
  25. draft='',
  26. sent='SENT'
  27. WHERE id='draftid'");}
  28.  
  29. header('Location: mailbox.php');
Save works just fine, but in the event I try to send it disregards the Save as I would expect it to, but it also disregards the rest of the script and just executes the header. Not quite sure what I'm doing wrong here. Any ideas would be greatly appreciated.
Similar Threads
Reputation Points: 21
Solved Threads: 31
Posting Pro in Training
CFROG is offline Offline
405 posts
since Jul 2009
Aug 6th, 2009
1

Re: One form, two actions

html Syntax (Toggle Plain Text)
  1. $send="INSERT INTO mailbox SET
  2. member_id='$memid',
  3. user_name='$$_SESSION[user_name]',
  4. user_id='$_SESSION[user_id]',
  5. message='$message',
  6. inbox='NEW',
  7. subject='$subject',
  8. date='$dsub' " ;
  9. $save_result=mysql_query($save);
  10.  
  11. // update draft to sent
  12. mysql_query("UPDATE mailbox SET
  13. draft='',
  14. sent='SENT'
  15. WHERE id='draftid'");
  16.  
  17. header('Location: mailbox.php');

How bout that....
u do insert and update then after that u give the header.......
is it works?
Reputation Points: 11
Solved Threads: 1
Newbie Poster
elreso is offline Offline
3 posts
since Nov 2007
Aug 6th, 2009
1

Re: One form, two actions

php Syntax (Toggle Plain Text)
  1. $send="INSERT INTO mailbox SET
  2. member_id='$memid',
  3. user_name='$$_SESSION[user_name]',
  4. user_id='$_SESSION[user_id]',
  5. message='$message',
  6. inbox='NEW',
  7. subject='$subject',
  8. date='$dsub' " ;
  9. $save_result=mysql_query($save);

What is $save? I think you are trying to run the query $send?
Reputation Points: 395
Solved Threads: 192
Veteran Poster
darkagn is offline Offline
1,136 posts
since Aug 2007
Aug 6th, 2009
0

Re: One form, two actions

I did catch the $send and changed it also removed an extra $ from SESSION[user] ... It is sending now, just not updating the 'draft' to a 'sent' mail at the bottom of the script. Still working on it.
Reputation Points: 21
Solved Threads: 31
Posting Pro in Training
CFROG is offline Offline
405 posts
since Jul 2009
Aug 6th, 2009
0

Re: One form, two actions

I got it ... finally! LOL. I was missing a "$" for my variable 'draftid' ... You stare at this stuff long enough and it's easy to overlook the little things. I almost feel foolish. Thank you guys, Problem Solved!
Reputation Points: 21
Solved Threads: 31
Posting Pro in Training
CFROG is offline Offline
405 posts
since Jul 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: How to Display Motherboard Serial With PHP
Next Thread in PHP Forum Timeline: how to add time duration in php





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC