Jump to content

PHP Help Desparately Requested


wantabe2

Recommended Posts

The attached code pulls data from a mysql database & displays it in a form so I can edit it. I need to be able, when a user clicks the submit button in this code, the data is updated in the mysql database, and sends that data to an email address based off of the location. At this time I just have first name, lastname, and location in there. So if a user chose office1 the data would go to office1@mail.com. Everything works except the email part.

 

I thought I had it earlier but was wrong. Can someone please assist? Thanks

 

 

 



<?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'])) ) { // Accessed through view_users.php
$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 mail according to location
switch($_REQUEST['location']) { 
case "office1":
$email = "myemail@yahoo.com";
break;
default:
echo "Error, no location selected!!!";
break; 
}
$Message = "<p>An employee has edited the information below.</p><br> 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 Review";
$Headers .= "To: DQA <$EmailAddress>\n"; 
$Headers .= "From: The Database <sender email>\n"; 
$SendMail = mail($EmailAddress, $Subject, $Message, $Headers);

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

echo "<center>An email has been sent for editing"; 
} else { 

echo "This system is not working properly. Please contact a tech."; 

}

$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.

?>



Link to comment
Share on other sites

That was a typo on my post. Below is the real code. I'm not even getting the message "An email has been sent for editing"

 

 



<?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'])) ) { // Accessed through view_users.php
$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 mail according to location
switch($_REQUEST['location']) { 
case "office1":
$emailaddress = "myemail@yahoo.com";
break;
default:
echo "Error, no location selected!!!";
break; 
}
$Message = "<p>An employee has edited the information below.</p><br> 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 Review";
$Headers .= "To: DQA <$EmailAddress>\n"; 
$Headers .= "From: The Database <sender email>\n"; 


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

echo "<center>An email has been sent for editing"; 
} else { 

echo "This system is not working properly. Please contact a tech."; 

}

$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.

?>



Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.