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?

LVL 1
movieprodwAsked:
Who is Participating?
 
movieprodwConnect With a Mentor Author Commented:
I am an idiot!

<input type="hidden" name="entry" value="<?php echo $entry ?>"> was in the form so it was what was entered into the db not the new info in the field, I deleted it  and it worked great!

AH!
0
 
krv123Connect With a Mentor Commented:
if(isset($_POST['email'])){
// $_POST[''] for details
}
if(isset($_POST['send'])){
// $_POST[''] for details
}
0
 
movieprodwAuthor Commented:
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

0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
CWS (haripriya)Connect With a Mentor Commented:
Try this
<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");?>'>	
<input class="propformsubmitText" name="save" id="save" type="submit" value="Save Entry">
<input class="propformsubmitText" name="email" id="email" type="submit" value="Email Entry" ></form>
 
 
 
 
 
 
 
 
 
 
 
 
<?
include('db.php');
session_start();
 
	$subject = 'subject';
	$to = $_POST['email'];
	$userid = $_SESSION['userid'];
	$entry = $_POST['entry'];
	$list_date = $_POST['list_date'];
 
if($_POST['submit']=="Save Entry"){
mysql_query("update notes set entry='$entry', list_date='$list_date' where userid='$userid'");
 
header("location:control_panel_notebook.php?msg=saved");
 
exit;
 
}
if($_POST['submit']=="Email Entry"){
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

0
 
krv123Commented:
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

0
 
krv123Commented:
line 10 and 11 dont have ; on the end of the varibles
0
 
movieprodwAuthor Commented:
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
0
 
krv123Commented:
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

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.