?
Solved

Two buttons one form, php

Posted on 2009-04-23
8
Medium Priority
?
782 Views
Last Modified: 2013-12-12
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?

0
Comment
Question by:movieprodw
  • 4
  • 3
8 Comments
 
LVL 1

Assisted Solution

by:krv123
krv123 earned 1200 total points
ID: 24217037
if(isset($_POST['email'])){
// $_POST[''] for details
}
if(isset($_POST['send'])){
// $_POST[''] for details
}
0
 
LVL 1

Author Comment

by:movieprodw
ID: 24217392
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
 
LVL 16

Assisted Solution

by:CWS (haripriya)
CWS (haripriya) earned 800 total points
ID: 24217580
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
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
LVL 1

Expert Comment

by:krv123
ID: 24217600
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
 
LVL 1

Expert Comment

by:krv123
ID: 24217930
line 10 and 11 dont have ; on the end of the varibles
0
 
LVL 1

Author Comment

by:movieprodw
ID: 24218473
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
 
LVL 1

Expert Comment

by:krv123
ID: 24218581
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
 
LVL 1

Accepted Solution

by:
movieprodw earned 0 total points
ID: 24218881
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

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In this article, we’ll look at how to deploy ProxySQL.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month17 days, 5 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question