Link to home
Start Free TrialLog in
Avatar of movieprodw
movieprodw

asked on

Two buttons one form, php

Hello I am sending a form and I have two buttons, one is named email and the other send.

I then have a php file that the form posts to I need them to do different things.

Any ideas without java?

SOLUTION
Avatar of krv123
krv123
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of movieprodw
movieprodw

ASKER

Hello,

I still can not get it to work, they both send the email and do not save it?!
<form id="subNote" name="subNote" method="post" action="post_note.php">
 
  
  <label><div class="labelblock">Entry</div>
  <textarea class="propformText" name="entry" id="entry" wrap="virtual" /><? echo $entry ?></textarea>
  </label>
 
<br>
<input type="hidden" name="userid" value='<?php echo $userid;?>'>
<input type="hidden" name="entry" value="<?php echo $entry ?>">
<input type="hidden" name="email" value="<?php echo $email ?>">
<input type="hidden" name="list_date" value='<?php echo date("Ymd");?>'>	
<button class="propformsubmitText" name="save" id="save" type="submit">Save Entry</button>
<button class="propformsubmitText" name="email" id="email" type="submit">Email Entry</button>
</form>
 
 
 
 
 
 
 
 
 
 
 
 
<?
include('db.php');
session_start();
 
	$subject = 'subject';
	$to = $_POST['email'];
	$userid = $_SESSION['userid'];
	$entry = $_POST['entry'];
	$list_date = $_POST['list_date'];
 
if(isset($_POST['save'])){
mysql_query("update notes set entry='$entry', list_date='$list_date' where userid='$userid'");
 
header("location:control_panel_notebook.php?msg=saved");
 
exit;
 
}
if(isset($_POST['email'])){
mysql_query("update notes set entry='$entry', list_date='$list_date' where userid='$userid'");
 
	$headers  = 'MIME-Version: 1.0' . "\r\n";
	$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $headers .= 'From: email@email.com' . "\r\n";
 
 
 
	$message = $message . "Below is your notebook entry from MySite.com:<br /><br />";
    $message = $message . $entry;
	$message = $message . "<br /><br />Thank you for using MySite.com for all of your real estate needs! <br />";
 
 
 
 
    //echo("The value received is " . $to .  "<BR>" . $subject .  "<BR>" . $message .  "<BR>" .$headers );
	mail ($to, $subject, $message, $headers);
	header("target: _self");
	header("Location: control_panel_notebook.php?msg=Your entry has been sent to '. $to .'!");
exit;
 
}
 
 
 
mysql_close();
?>

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
first lets see whats wrong with your query run that and paste the mysql error.
include('db.php');
session_start();
 
        $subject = 'subject';
        $to = $_POST['email'];
        $userid = $_SESSION['userid'];
        $entry = $_POST['entry'];
        $list_date = $_POST['list_date'];
 
if(isset($_POST['save'])){
mysql_query("update notes set entry='$entry', list_date='$list_date' where userid='$userid'")or die(mysql_error());
 
header("location:control_panel_notebook.php?msg=saved");
 
exit;
 
}
if(isset($_POST['email'])){
mysql_query("update notes set entry='$entry', list_date='$list_date' where userid='$userid'")or die(mysql_error());
 
        $headers  = 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
   		$headers .= 'From: email@email.com' . "\r\n";
 
 
 
        $message = $message . "Below is your notebook entry from MySite.com:<br /><br />";
    	$message = $message . $entry;
        $message = $message . "<br /><br />Thank you for using MySite.com for all of your real estate needs! <br />";
 
 
    	//echo("The value received is " . $to .  "<BR>" . $subject .  "<BR>" . $message .  "<BR>" .$headers );
        mail ($to, $subject, $message, $headers);
        header("target: _self");
        header("Location: control_panel_notebook.php?msg=Your entry has been sent to '. $to .'!");
exit;
 
}
 
mysql_close();

Open in new window

line 10 and 11 dont have ; on the end of the varibles
nice catch krv123

I did fix those and when I run it it its does pick out the button and run the contents but it does not insert the data into the table, it will only send the emial, it just returns back to the page as it should
try this and see if you get an error, if you do post it.
 $sql = "UPDATE notes SET entry='$entry',list_date='$list_date' WHERE userid='$userid'";
 $result = mysql_query($sql)or die(mysql_error());
 if($result){
 	echo 'success';
 }

Open in new window

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial