954,160 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

One form, two actions

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:

<input type="submit" name="save" id="save" value="Save as Draft" />
<input type="submit" name="send" id="send" value="Send" />

Here is how I'm trying to differentiate between form actions.

if(isset($_POST['save']) && trim($_POST["save"])!==''){
	mysql_query("UPDATE mailbox SET 
		member_id='$_SESSION[user_id]',
		message='$message',
		draft='DRAFT',
		subject='$subject',
		date='$dsub' 
		WHERE id='$draftid'");
	header('Location: mailbox.php');

}elseif(isset($_POST['send']) && trim($_POST["send"])!==''){
	$send="INSERT INTO mailbox SET
		member_id='$memid',
		user_name='$$_SESSION[user_name]',
		user_id='$_SESSION[user_id]',
		message='$message',
		inbox='NEW',
		subject='$subject',
		date='$dsub' " ;
	$save_result=mysql_query($save);
header('Location: mailbox.php');

		// update draft to sent
	mysql_query("UPDATE mailbox SET
		draft='',
		sent='SENT'
		WHERE id='draftid'");}
	
	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.

CFROG
Posting Pro in Training
408 posts since Jul 2009
Reputation Points: 21
Solved Threads: 31
 
$send="INSERT INTO mailbox SET
	member_id='$memid',
	user_name='$$_SESSION[user_name]',
	user_id='$_SESSION[user_id]',
	message='$message',
	inbox='NEW',
	subject='$subject',
	date='$dsub' " ;
$save_result=mysql_query($save);

// update draft to sent
mysql_query("UPDATE mailbox SET
	draft='',
	sent='SENT'
	WHERE id='draftid'");

header('Location: mailbox.php');


How bout that....
u do insert and update then after that u give the header.......
is it works?

elreso
Newbie Poster
3 posts since Nov 2007
Reputation Points: 11
Solved Threads: 1
 
$send="INSERT INTO mailbox SET
   member_id='$memid',
   user_name='$$_SESSION[user_name]',
   user_id='$_SESSION[user_id]',
   message='$message',
   inbox='NEW',
   subject='$subject',
   date='$dsub' " ;
$save_result=mysql_query($save);


What is $save? I think you are trying to run the query $send?

darkagn
Veteran Poster
1,197 posts since Aug 2007
Reputation Points: 404
Solved Threads: 200
 

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.

CFROG
Posting Pro in Training
408 posts since Jul 2009
Reputation Points: 21
Solved Threads: 31
 

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!

CFROG
Posting Pro in Training
408 posts since Jul 2009
Reputation Points: 21
Solved Threads: 31
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You