Link to home
Start Free TrialLog in
Avatar of wantabe2
wantabe2Flag for United States of America

asked on

PHP Help Needed

Can someone take a look at line 36 in this code?

This code pulls data from a MySQL database & displays it in a form. Then I can edit the data & click submit & it updates the MySQL database. It then, sends an email to the email address on line 35. Again, all of this works until I start editing line 36 to send the location, first name, & last name within the message of the email.

What is the code so I can get an email with the first name, last name & location?
<?php # edit_dqa.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'])) ) { // Form has been submitted.
	$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'); 
	exit();
}
		
		$query = "UPDATE psrinfo SET fname='$fn', lname='$ln', location='$loc' WHERE fid=$id";
		$result = @mysql_query ($query); // Run the query.
				
	// Send Email
	switch ('location') {
	case 'location1':
	echo $EmailAddress = 'myemail@yahoo.com';
	break;
	
	}
	
$EmailAddress = 'myemail@yahoo.com';	
$Message = "Someone has edited the information below."; Location : {$_REQUEST['location']}<br>First Name : {$_REQUEST['fname']}<br>Last Name : {$_REQUEST['lname']}"
$Headers  = "MIME-Version: 1.0\n"; 
$Headers = "Content-type: text/html; charset=iso-8859-1\n"; 
$Subject  = "Please Change";
$Headers = "To: DQA <$EmailAddress>\n"; 
$Headers = "From: anotheremail@yahoo.com \n"; 

if (mail($EmailAddress, $Subject, $Message, $Headers)) {
						
$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
if ((substr($url, -1) == '/') OR (substr($url, -1) == '//')) {
$url = substr ($url, 0, -1);
}
$url ='/flow/index.html'; 

header("Location: $url");

exit();
		
	} else { // Report the errors.
	
		echo '<h1 id="mainhead">Error!</h1>
		<p class="error">The following error(s) occurred:<br />';
		foreach ($errors as $msg) { // Print each error.
			echo " - $msg<br />\n";
		}
		echo '</p><p>Please try again.</p><p><br /></p>';
		
	} // End of if (empty($errors)) IF.

} // End of submit conditional.

// Retrieve the user's information.
$query = "SELECT pacts, fname, lname, location WHERE fid = " . $_REQUEST['id'];
$result = @mysql_query ($query); // Run the query.

if (mysql_num_rows($result) == 1) { // Valid user ID, show the form.

	$row = mysql_fetch_array ($result, MYSQL_NUM);
		
?>	

<?php

echo '<form action="edit_dqa.php" method="post">
<fieldset><legend><h1> You are editing a record!</h1></legend>

<b>First Name:</b> <br><input type="text" name="fname" size="15" maxlength="30" value="'.$row[1].'" /><br />
<b>Last Name:</b> <br><input type="text" name="lname" size="15" maxlength="30" value="'.$row[2].'" /><br />
<b>Location: </b><br><input type="text" name="location" size="15" maxlength="30" value="'.$row[5].'" /><br>
br>
<br>
</fieldset>

<div align="left"><input type="submit" name="submit" value="Submit" /></div>

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

} 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

Avatar of CombatGold1
CombatGold1

You keep overwriting the existing $Headers line with new ones, which will result in the header only containing "From: anotheremail@yahoo.com \n";

To append text onto the end of a string, you need to use a dot before the equals sign:
$Headers = "First line\n";
$Headers .= "Add this line\n";
$Headers .= "Add another line\n";
$Headers = "Actually erase those 3 lines, just have this line instead\n";

Open in new window


Also line 36 looks invalid. I'm guessing you want it to be something like this:
$Message = "Someone has edited the information below. Location : ${_REQUEST['location']}<br>\nFirst Name : ${_REQUEST['fname']}<br>\nLast Name : ${_REQUEST['lname']}";

Open in new window

Avatar of wantabe2

ASKER

Thanks, I did what you advised & it works perfect!

Is there any way I can add some kind of confirmation such as "Your edited information has been submitted" on the user end after they click on the "submit" button? Thanks again!
ASKER CERTIFIED SOLUTION
Avatar of CombatGold1
CombatGold1

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
Thanks, still not working but I will open up a new post.