PHP Coding Help Requested

Posted on 2011-04-29
Last Modified: 2012-05-11
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 = '';	
$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: \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

Question by:wantabe2
    LVL 50

    Expert Comment

    by:Steve Bink
    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?
    LVL 15

    Author Comment

    I need it to submit it & also send an email
    LVL 50

    Accepted Solution

    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 ( ....the original link I got it from now forwards somewhere else) and phpmailer (  They are both relatively easy to implement, and make the creation of mime-based email extremely simple.

    Featured Post

    Live: Real-Time Solutions, Start Here

    Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

    Join & Write a Comment

    Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
    This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
    In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
    In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

    755 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

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now