Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 282
  • Last Modified:

PHP Coding Help Requested

The attached code works fine. I need to edit it to do the following though...On lines 129 - 136, If a user chooses "employee1" from the drop down box, I'd like for employee1 to get a simple email with the other form information in this code such as first name, last name, etc.

Is this possible?
<body bgcolor=""> 

<?php # assign1.php

$page_title = 'Edit a Record';

$con = mysql_connect("localhost","uname","password");
if (!$con)
  die('Could not connect: ' . mysql_error());

mysql_select_db("psrflow", $con);


if ( (isset($_GET['id'])) && (is_numeric($_GET['id'])) ) { 
	$id = $_GET['id'];
} elseif ( (isset($_POST['id'])) && (is_numeric($_POST['id'])) ) {
	$id = $_POST['id'];
} else { // No valid ID, kill the script.
	echo '<h1 id="mainhead">Page Error</h1>
	<p class="error">This page has been accessed in error.</p><p><br /><br /></p>';
	include ('./includes/footer.html'); 

if (isset($_POST['submitted'])) {

	$errors = array();
	if (empty($_POST['fname'])) {
		$errors[] = 'You forgot to enter the first name.';
	} else {
		$fn = $_POST['fname'];
	if (empty($_POST['lname'])) {
		$errors[] = 'You forgot to enter the last name.';
	} else {
		$ln = $_POST['lname'];
		if (empty($_POST['location'])) {
		$errors[] = 'You forgot to enter a location.';
	} else {
		$loc = $_POST['location'];
		if (empty($_POST['employee'])) {
		$errors[] = 'You forgot to enter a employee.';
	} else {
		$off = $_POST['employee'];
			if (empty($_POST['cust'])) {
		$errors[] = 'You forgot to enter a cust number.';
	} else {
		$cust = $_POST['cust'];
			if (empty($_POST['mname'])) {
		$errors[] = 'You forgot to enter a middle name. If none, please enter NONE';
	} else {
		$mn = $_POST['mname'];
	if (empty($errors)) { 
	$query = "UPDATE psrinfo SET fname='$fn', lname='$ln', location='$loc', employee='$off', cust='$cust', mname='$mn' WHERE fid=$id";
	$result = mysql_query($query);
			if (mysql_affected_rows() == 1)
	echo '<p><b><center>The assignment has been submitted successfully! </p><p>An email containing all this information has been sent to the assigned employee.</b></p></center>';
$EmailAddress = 'employee1@yahoo.com';	
$Message = "A PSR Has Been Assigned to You. below.\n \n Name : ${_REQUEST['fname']} ${_REQUEST['mname']} ${_REQUEST['lname']} \ncust No : ${_REQUEST['cust']} \nemployee : ${_REQUEST['employee']} \nLocation : ${_REQUEST['location']}";
$Subject  = "PODDS Assignment";
$Headers = "From: PODDS@yahoo.com \n"; 

 	if (mail($EmailAddress, $Subject, $Message, $Headers)) 

	} else { 
		echo '<h1 id="mainhead">Error!</h1>
		<p class="error">The following error(s) occurred:<br />';
		foreach ($errors as $msg) { 
			echo " - $msg<br />\n";
		echo '</p><p><b>If you continue to get this error call a tech.</b></p><p><br /></p>';


$query = "SELECT fname, lname, location, cust, mname FROM psrinfo WHERE fid = " . $_REQUEST['id'];
$result = @mysql_query ($query); // Run the query.

if (mysql_num_rows($result) == 1) { 

	$row = mysql_fetch_array ($result, MYSQL_NUM);


echo '<form action="assign1.php" method="post">
<legend><h3> This section is for employee assignment only. The employee this client is assigned to will get an email. You DQA will not be notified until the employee enters the P1 information.</h2></legend>

<table width="95%" border="1">
<td><b>cust No:</b> <br><input type="text" name="cust" size="15" maxlength="30" value="'.$row[3].'" /><br> </td>
<td><b>Sentence Location: </b><br><input type="text" name="location" size="15" maxlength="30" value="'.$row[2].'" /><br></td>

<td><b>First Name:</b> <br><input type="text" name="fname" size="15" maxlength="30" value="'.$row[0].'" /><br /> </td>
<td><b>Middle Name:</b> <br><input type="text" name="mname" size="15" maxlength="30" value="'.$row[4].'" /><br /> </td>
<td><b>Last Name (Corporation/Partnership):</b> <br><input type="text" name="lname" size="25" maxlength="30" value="'.$row[1].'" /><br /> </td>

<b>Assign employee:<br> 
<select name="employee"> 
<option value=""></option>
<option value="employee1">employee1</option>
<option value="employee2"> employee2</option>
<option value="employee3"> employee3</option>
</select> </td>


<div align="left"><input type="submit" name="submit" value="Assign to employee" /></div>

<input type="hidden" name="submitted" value="TRUE"  />
<input type="hidden" name="id" value="' . $id . '" />

} else { // Not a valid user ID.
	echo '<h1 id="mainhead">Page Error</h1>
	<p class="error">This page has been accessed in error.</p><p><br /><br /></p>';

mysql_close(); // Close the database connection.


Open in new window

  • 2
1 Solution
Steve BinkCommented:
Do you want to submit the form again with that information?  Or do you just want an email to fire off without a form submission?
wantabe2Author Commented:
I need it to submit it & also send an email
Steve BinkCommented:
That is simple enough.  The form's handler (the page to which the form submits) should detect and scrub all the input.  Your own code already shows examples of that.  Then just put the contents of the email in a string variable.  To send the email, you will use the mail() function:


If you want to send HTML emails, I would recommend getting a third-party mailing class that generates the proper format.  Two popular ones are Richard Haye's HTMLMimeMail (http://www.phpclasses.org/package/32-PHP-A-class-for-sending-mime-email-.html ....the original link I got it from now forwards somewhere else) and phpmailer (http://phpmailer.worxware.com/).  They are both relatively easy to implement, and make the creation of mime-based email extremely simple.

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now