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.

$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?

$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?

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.

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.