Guest Posted March 18, 2011 Share Posted March 18, 2011 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. ?> Quote Link to comment https://forums.phpfreaks.com/topic/231001-php-code-issue/ Share on other sites More sharing options...
KevinM1 Posted March 18, 2011 Share Posted March 18, 2011 Take a look at the text highlighting in the code you just posted. You're missing a semicolon at the end of your $message = ... line. Also, your switch shouldn't be working, as location isn't a variable, it's a string. 'location' will never be 'location1'. Quote Link to comment https://forums.phpfreaks.com/topic/231001-php-code-issue/#findComment-1189106 Share on other sites More sharing options...
Guest Posted March 18, 2011 Share Posted March 18, 2011 Thanks, I've edited the code & now it works great, thanks. Is there any way for me to add some lines of code below line 36 so the user who clicks the submit button will get some type of confirmation message/box telling them the email has been sent? The updated code is attached. <?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. $EmailAddress = 'myemail@yahoo.com'; $Message = "Someone has edited the information below. Location : ${_REQUEST['location']}\nFirst Name : ${_REQUEST['fname']}\nLast Name : ${_REQUEST['lname']}"; $Subject = "Please Change"; $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. ?> Quote Link to comment https://forums.phpfreaks.com/topic/231001-php-code-issue/#findComment-1189127 Share on other sites More sharing options...
KevinM1 Posted March 18, 2011 Share Posted March 18, 2011 Do you want the user to remain on the same page after the email is sent? Quote Link to comment https://forums.phpfreaks.com/topic/231001-php-code-issue/#findComment-1189289 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.