Guest Posted July 2, 2012 Share Posted July 2, 2012 I have this PHP script on my website that pulls some data from my MySQL database & displays it on a form. The user them adds additional items to the form & then clicks submit & all of the information on the form is emailed to a secretary. In the database, I have a field named active & it is either set to 0 or 1. Is it possible to edit this code so when the user clicks the submit button the email still gets sent but in addition it marks the "active" field in teh databae to a 1? <p> <b> <i>To go to the main page <a href="http://mysite/flow/index.html">click here</a>.</b> </i></p> <?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); ini_set('display_errors',1); error_reporting(E_ALL); if ( (isset($_GET['id'])) && (is_numeric($_GET['id'])) ) { $id = $_GET['id']; } elseif ( (isset($_POST['id'])) && (is_numeric($_POST['id'])) ) { $id = $_POST['id']; } else { 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(); } if (isset($_POST['submitted'])) { $errors = array(); if (empty($_POST['pnumber'])) { $errors[] = 'You forgot to enter your pnumber number. If there is no pnumber # you can enter 0000'; } else { $pt = $_POST['pnumber']; } if (empty($_POST['customer_fname'])) { $errors[] = 'You forgot to enter the customers first name.'; } else { $fn = $_POST['customer_fname']; } if (empty($_POST['customer_lname'])) { $errors[] = 'You forgot to enter the customers last name.'; } else { $ln = $_POST['customer_lname']; } if (empty($_POST['employee1'])) { $errors[] = 'You forgot to enter a employee1.'; } else { $off = $_POST['employee1']; } if (empty($_POST['custnom'])) { $errors[] = 'You forgot to enter a custnom number.'; } else { $dkt = $_POST['custnom']; } if (empty($_POST['customer_mname'])) { $errors[] = 'You forgot to enter a middle name. If none, please enter NONE'; } else { $mn = $_POST['customer_mname']; } if (empty($_POST['district'])) { $errors[] = 'You forgot to enter a district'; } else { $dist = $_POST['district']; } if (empty($_POST['dft_no'])) { $errors[] = 'You forgot to enter a unlucky number'; } else { $dft_no = $_POST['dft_no']; } if (empty($errors)) { if (mysql_affected_rows() == 1) echo '<p><b><center>This information has been submitted successfully! </p><p>An email containing all this information has been sent to your secretary to update pnumber for this customer.</b></p></center>'; $EmailAddress = 'theemail@yahoo.com'; $Message = "Someone has submitted the information below.\n \n \nemployee1 Notes : ${_REQUEST['notes']}\n\npnumber No : ${_REQUEST['pnumber']} \nemployee1 : ${_REQUEST['employee1']} \ncustomer Name : ${_REQUEST['customer_fname']} ${_REQUEST['customer_mname']} ${_REQUEST['customer_lname']} \nDistrict (State if not ED/TN) : ${_REQUEST['district']} \ncustnom No : ${_REQUEST['custnom']} \nunlucky No : ${_REQUEST['dft_no']} \n \nSent Date : ${_REQUEST['sent_date']} \nAdjudication Date : ${_REQUEST['adjud_date']} \nOffense Level : ${_REQUEST['tol']} \nHistory Points : ${_REQUEST['chp']} \ncustomer Type : ${_REQUEST['too']} \nTest Waiver : ${_REQUEST['dtwav']} \ntheboss Name : ${_REQUEST['theboss_name']} \nSent Type : ${_REQUEST['sent_type']} \nTime : ${_REQUEST['pt']} ${_REQUEST['time_mdy']} \nInside Start Date : ${_REQUEST['psd']} \nTSR Time : ${_REQUEST['tsr_time']} ${_REQUEST['tsr_mdy']} \nWatch Time : ${_REQUEST['prob_time']} ${_REQUEST['pro_mdy']} \nConditional Release : ${_REQUEST['cond_rel']} \nSpecial Assessment : ${_REQUEST['spec_asse']} \nWhy Is Interest Waived : ${_REQUEST['faiw']} ${_REQUEST['int_waved']} \nIs Interest Waived : ${_REQUEST['raiw']} ${_REQUEST['intr_waved']} \n\nClosing Date : ${_REQUEST['close_date']} \nDisposition : ${_REQUEST['disposition']} "; $Subject = "ItHas Been Submitted"; $Headers = "From: PODDS@tnep.uscourts.gov \n"; if (mail($EmailAddress, $Subject, $Message, $Headers)) echo '<p><b><center>This information has been submitted successfully!</center>'; exit(); } 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>Please try again. You must have forgot to enter something. If you continue to get this error call IT.</b></p><p><br /></p>'; } } $query = "SELECT pnumber, customer_fname, customer_lname, status, employee1, sent_date, custnom, customer_mname, district, dft_no, jud_off_name, assgn_date FROM psrinfo WHERE fid = " . $_REQUEST['id']; $result = @mysql_query ($query); if (mysql_num_rows($result) == 1) { $row = mysql_fetch_array ($result, MYSQL_NUM); ?> <?php echo '<form action="p2.php" method="post"> <h2> <center>pnumber Sentence Date Form. After submitting this information, your secretary will be notified. <center>(P-2)</h2></center></h2> <table width="95%" border="1"> <tr> <td><b>pnumber No:</b> <br><input type="text" name="pnumber" size="15" maxlength="30" value="'.$row[0].'" /><br> </td> <td><b></b> <br><name="" value="" /><br> </td> <td><b>employee1: </b><br><input type="text" name="employee1" size="15" maxlength="30" value="'.$row[4].'" /><br></td> </tr> <tr> <td><b>First Name:</b> <br><input type="text" name="customer_fname" size="15" maxlength="30" value="'.$row[1].'" /><br /> </td> <td><b>Middle Name:</b> <br><input type="text" name="customer_mname" size="15" maxlength="30" value="'.$row[7].'" /><br /> </td> <td><b>Last Name (Corporation/Partnership):</b> <br><input type="text" name="customer_lname" size="25" maxlength="30" value="'.$row[2].'" /><br /> </td> </tr> <td><b>District (State if not ED/TN): <select name="district"> <option value="ED/TN">ED/TN</option> <option value="AL"> AL</option> <option value="AK"> AK</option> <option value="AS"> AS</option> <option value="AZ"> AZ</option> <option value="AR"> AR</option> </select> </td> </br> <td><b>custnom No:</b> <br><input type="text" name="custnom" size="15" maxlength="30" value="'.$row[6].'" /><br> </td> <td><b>unlucky No:</b><br><input type="text" name="dft_no" size="15" maxlength="30" value="'.$row[9].'" /> <br> </td> </tr> <tr> <td><b>Final Date YYYY-MM-DD:</b><br><input type="text" name="sent_date" size="15" maxlength="30" value="'.$row[5].'" /> <br></td> <td><b>Determination Date:</b><br><input type="text" name="adjud_date" size="15" maxlength="30" value="'.$row[11].'" /> <br></td> <td><b>Total Level (0-50):</b><br><input type="text" name="tol" size="15" maxlength="30" /> <br></td> <td><b>History Points (0-50):</b><br><input type="text" name="chp" size="15" maxlength="30" /> <br></td> </tr> <tr> <td> <b>customer Type:<br> <select name="too"> <option value="N/A">N/A</option> <option value="Juvenile">Juvenile</option> <option value="Career customer">Career customer</option> <option value="Sealed">Sealed</option> </select> </td> <td> <b>Test Waiver:<br> <select name="dtwav"> <option value="No">No</option> <option value="Yes">Yes</option> </select> </td> <td><b>theboss Name:</b> <br><input type="text" name="theboss_name" size="20" maxlength="30" value="'.$row[10].'" /><br> </td> <td> <b>Sent Type:<br> <select name="sent_type"> <option value="Choose One">Choose One</option> <option value="Original">Original</option> <option value="Amended">Amended</option> </select> </td> </tr> <tr> <td><b>Inside Time:</b><br><input type="text" name="pt" size="25" maxlength="30" value="N/A"/> <select name="time_mdy"> <option value="N/A">N/A</option> <option value="Days">Days</option> <option value="Months">Months</option> </select><br></td> <td><b>Start Date:</b><br><input type="text" name="psd" size="25" maxlength="30" value="N/A" /> <br></td> <td><b>TSR Time:</b><br><input type="text" name="tsr_time" size="25" maxlength="30" value="N/A" /> <select name="tsr_mdy"> <option value="N/A">N/A</option> <option value="Months">Months</option> </select><br></td> <td><b>Watch Time:</b><br><input type="text" name="prob_time" size="25" maxlength="30" value="N/A" /> <select name="pro_mdy"> <option value="N/A">N/A</option> <option value="Months">Months</option> <option value="Days">Days</option> </select><br></td></tr> <tr> <td> <b>Release:<br> <select name="cond_rel"> <option value="N/A">N/A</option> <option value="Yes">Yes</option> <option value="No">No</option> </select> </td> <td><b>Assessment:</b><br><input type="text" name="spec_asse" size="25" maxlength="30" value="N/A"/> <br></td> <td><b>Is Interest Waived?</b><br><input type="text" name="faiw" size="25" maxlength="30" value="N/A" /> <select name="int_waved"> <option value="N/A">N/A</option> <option value="Yes">Yes</option> <option value="No">No</option> </select><br></td> <td><b>Why Is Interest Waived?</b><br><input type="text" name="raiw" size="25" maxlength="30" value="N/A" /> <select name="intr_waved"> <option value="N/A">N/A</option> <option value="Yes">Yes</option> <option value="No">No</option> </select><br></td></tr> </tr> <tr> <td><b>Closing Date:</b><br><input type="text" name="close_date" size="25" maxlength="30" value="YYYY-MM-DD" /> <br></td> <td> <b>Disposition:<br> <select name="disposition"> <option value="Choose One">Choose One</option> <option value="Close Courtesy Only">Close Courtesy Only</option> </select> <td> <b>employee1 Notes: </b> <b></b> <textarea name = "notes" rows=3 cols=50>N/A</textarea> </br> </td> </tr> </table>      <div align="left">            <input type="submit" name="submit" value="Submit" /></div></td> <input type="hidden" name="submitted" value="TRUE" /> <input type="hidden" name="id" value="' . $id . '" /> </form>'; } else { echo '<h1 id="mainhead">Page Error</h1> <p class="error">This page has been accessed in error.</p><p><br /><br /></p>'; } mysql_close(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/265117-php-help-needed/ Share on other sites More sharing options...
Barand Posted July 2, 2012 Share Posted July 2, 2012 When you send the email, mysql_query("UPDATE yourtablename SET active=1 WHERE id = $id"); where id is the primary key and $id is the value Quote Link to comment https://forums.phpfreaks.com/topic/265117-php-help-needed/#findComment-1358624 Share on other sites More sharing options...
Guest Posted July 2, 2012 Share Posted July 2, 2012 So I would add mysql_query("UPDATE yourtablename SET active=1 WHERE id = $id"); under if (mail($EmailAddress, $Subject, $Message, $Headers)) if (mail($EmailAddress, $Subject, $Message, $Headers)) mysql_query("UPDATE yourtablename SET active=1 WHERE id = $id"); ?? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/265117-php-help-needed/#findComment-1358626 Share on other sites More sharing options...
Barand Posted July 2, 2012 Share Posted July 2, 2012 Yes, that's it. Quote Link to comment https://forums.phpfreaks.com/topic/265117-php-help-needed/#findComment-1358627 Share on other sites More sharing options...
Guest Posted July 3, 2012 Share Posted July 3, 2012 I added this & it didn't work: if (mail($EmailAddress, $Subject, $Message, $Headers)) mysql_query("UPDATE yourtablename SET active=1 WHERE id = $id"); The email was sent but the active field remained a 0 & was not changed to a 1. Any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/265117-php-help-needed/#findComment-1358802 Share on other sites More sharing options...
Jessica Posted July 3, 2012 Share Posted July 3, 2012 Um. Did you change yourtablename to the name of the actual table? Quote Link to comment https://forums.phpfreaks.com/topic/265117-php-help-needed/#findComment-1358841 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.