One form, two actions

Thread Solved

Join Date: Jul 2009
Posts: 220
Reputation: CFROG is an unknown quantity at this point 
Solved Threads: 14
CFROG's Avatar
CFROG CFROG is offline Offline
Posting Whiz in Training

One form, two actions

 
0
  #1
Aug 5th, 2009
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:
  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.
  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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3
Reputation: elreso is an unknown quantity at this point 
Solved Threads: 1
elreso's Avatar
elreso elreso is offline Offline
Newbie Poster

Re: One form, two actions

 
1
  #2
Aug 6th, 2009
  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?
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 799
Reputation: darkagn has a spectacular aura about darkagn has a spectacular aura about darkagn has a spectacular aura about 
Solved Threads: 110
darkagn's Avatar
darkagn darkagn is offline Offline
Master Poster

Re: One form, two actions

 
1
  #3
Aug 6th, 2009
  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?
There are no stupid questions, only those too stupid to ask for help.
echo is a web developer's best friend.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 220
Reputation: CFROG is an unknown quantity at this point 
Solved Threads: 14
CFROG's Avatar
CFROG CFROG is offline Offline
Posting Whiz in Training

Re: One form, two actions

 
0
  #4
Aug 6th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 220
Reputation: CFROG is an unknown quantity at this point 
Solved Threads: 14
CFROG's Avatar
CFROG CFROG is offline Offline
Posting Whiz in Training

Re: One form, two actions

 
0
  #5
Aug 6th, 2009
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!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC