Code Help Needed

Posted on 2011-04-26
Last Modified: 2012-06-21
The attached code pulls data from my MySQL database & displays it in a browser. You can then edit what is displayed in the browser & click the "submit" button & it will update the record in the MySQL database.

I did not write this code & know just enough to be dangerous. I have added a field named new_sent_time. This field will pull data from my MySQL database & display it in the browser but if I try to update that field & then click submit, it does not update the MySQL database...Can someone take a look at this & help me out? The new field is added on lines 215 -216. Thanks
<b> <p> <i> To go to the main page <a href="">click here</a>.</p> </i>


$page_title = 'Edit a Record';

$con = mysql_connect("localhost","uname","pword");
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 { 
	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['pacts'])) {
		$errors[] = 'You forgot to enter your PACTS number. If there is no PACTS # you can enter 0000';
	} else {
		$pt = $_POST['pacts'];
	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['status'])) {
		$errors[] = 'You forgot to enter a status.';
	} else {
		$st = $_POST['status'];
		if (empty($_POST['due_rev'])) {
		$errors[] = 'You forgot to enter a due to reviewer date.';
	} else {
		$rv = $_POST['due_rev'];
		if (empty($_POST['due_suspo'])) {
		$errors[] = 'You forgot to enter a due to SUSPO date.';
	} else {
		$sus = $_POST['due_suspo'];
		if (empty($_POST['due_clerk'])) {
		$errors[] = 'You forgot to enter a due to clerk date.';
	} else {
		$clk = $_POST['due_clerk'];
		if (empty($_POST['due_owner'])) {
		$errors[] = 'You forgot to enter a due to owner date.';
	} else {
		$jdg = $_POST['due_owner'];
		if (empty($_POST['location'])) {
		$errors[] = 'You forgot to enter a location.';
	} else {
		$loc = $_POST['location'];
		if (empty($_POST['office'])) {
		$errors[] = 'You forgot to enter a office.';
	} else {
		$off = $_POST['office'];
		if (empty($_POST['sent_date'])) {
		$errors[] = 'You forgot to enter a sentence date.';
	} else {
		$sd = $_POST['sent_date'];
		if (empty($_POST['due_attny'])) {
		$errors[] = 'You forgot to enter an attorney date.';
	} else {
		$atn = $_POST['due_attny'];
	if (empty($errors)) { 
	$query = "UPDATE psrinfo SET pacts='$pt', fname='$fn', lname='$ln', status='$st', location='$loc', office='$off', sent_date='$sd', due_rev='$rv', due_suspo='$sus', due_clerk='$clk', due_attny='$atn', due_owner='$jdg', new_sent_time= '$nst'  WHERE fid=$id";
	$result = @mysql_query ($query); 
$EmailAddress = '';	
$Message = "Someone has edited the information below.\n \nPACTS No : ${_REQUEST['pacts']}\nLocation : ${_REQUEST['location']}\nOffender Name : ${_REQUEST['fname']} ${_REQUEST['lname']} \nStatus : ${_REQUEST['status']} \noffice : ${_REQUEST['office']} \nDue to GS : ${_REQUEST['due_rev']} \nDue to SUSPO : ${_REQUEST['due_suspo']} \nDue to Attorney : ${_REQUEST['due_attny']} \nDue to Clerk : ${_REQUEST['due_clerk']} \nDue to owner : ${_REQUEST['due_owner']} \nSentence Date : ${_REQUEST['sent_date']} ";	
$Subject  = "Please Change in PACTS";
$Headers = "From: \n"; 

if (mail($EmailAddress, $Subject, $Message, $Headers)) {
echo "<p><center><h2>Your information has been updated!</h2></center></p>";
echo "<center>An email has been sent to your DQA. "; 
} else { 
echo "This system is not working properly. Please contact IT so he can fix it."; 
$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
if ((substr($url, -1) == '/') OR (substr($url, -1) == '//')) {
$url = substr ($url, 0, -1);

	} else { 
		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>';


$query = "SELECT pacts, fname, lname, status, office, location, sent_date, oth_date, due_rev, due_suspo, due_clerk, due_attny, due_owner, new_sent_time FROM psrinfo WHERE fid = " . $_REQUEST['id'];
$result = @mysql_query ($query); 

if (mysql_num_rows($result) == 1) { 

	$row = mysql_fetch_array ($result, MYSQL_NUM);

<script type="text/javascript">
var valid;

function d2(v) { return (v<10)?("0"+v):v; }

function dcheck(form) {
var s = form.sent_date.value;
var dr = form.due_rev.value
var su = form.due_suspo
var clk = form.due_clerk
var att = form.due_attny
var jdg = form.due_owner
var nst = form.new_sent_time
var sent = new Date(s);
var due_rev = new Date(dr);
var due_suspo = new Date(su);
var due_clerk = new Date(clk);
var due_attny = new Date(att);
var due_owner = new Date(jdg);
var new_sent_time = new Text(nst);

if (isNaN(due_rev)) {
due_rev = new Date(sent.getFullYear(),sent.getMonth(),sent.getDate()-42);
if (isNaN(due_suspo)) {
due_suspo = new Date(sent.getFullYear(),sent.getMonth(),sent.getDate()-40);
if (isNaN(due_clerk)) {
due_clerk = new Date(sent.getFullYear(),sent.getMonth(),sent.getDate()-38);
if (isNaN(due_attny)) {
due_attny = new Date(sent.getFullYear(),sent.getMonth(),sent.getDate()-36);
if (isNaN(due_owner)) {
due_owner = new Date(sent.getFullYear(),sent.getMonth(),sent.getDate()-7);

form.sent_date.value = (sent.getFullYear()+0) + "-" + d2(sent.getMonth()+1) + "-" + d2(sent.getDate());
form.due_rev.value = (due_rev.getFullYear()+0) + "-" + d2(due_rev.getMonth()+1) + "-" + d2(due_rev.getDate());
form.due_suspo.value = (due_suspo.getFullYear()+0) + "-" + d2(due_suspo.getMonth()+1) + "-" + d2(due_suspo.getDate());
form.due_clerk.value = (due_clerk.getFullYear()+0) + "-" + d2(due_clerk.getMonth()+1) + "-" + d2(due_clerk.getDate());
form.due_attny.value = (due_attny.getFullYear()+0) + "-" + d2(due_attny.getMonth()+1) + "-" + d2(due_attny.getDate());
form.due_owner.value = (due_owner.getFullYear()+0) + "-" + d2(due_owner.getMonth()+1) + "-" + d2(due_owner.getDate());

return true;


echo '<form action="edit_dqa.php" method="post">
<fieldset><legend><h2> You are editing a record! After submitting this form, your DQA will be notified of the change via email.</h2></legend>

<b>PACTS No:</b> <br><input type="text" name="pacts" size="15" maxlength="30" value="'.$row[0].'" /><br>
<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>Status: </b><br><input type="text" name="status" size="15" maxlength="30" value="'.$row[3].'" /> <br>
<b>Location: </b><br><input type="text" name="location" size="15" maxlength="30" value="'.$row[5].'" /><br>
<b>office: </b><br><input type="text" name="office" size="15" maxlength="30" value="'.$row[4].'" /> <br>

<td><b>New Sentence Time? (If no new sentence time, please leave as is)</b> <br />
<input type="text" name="new_sent_time" size="30" value= "'.$row[13].'"><br />

<b>Sentence Date: (Example: MM/DD/YYYY) </b><br><input type="text" name="sent_date" size="15" maxlength="30" value="'.$row[7].'" /> <br>

<p><input type="button" value="Calculate"  onclick="return dcheck(this.form);">	 <br>

<br> <div align="left"><input type="submit" name="submit" value="Submit" /> <u>Do Not Edit Anything Below This Line</u></div>

<b>----------------------------------------------------------------</b> <br />

<b>Due to Reviewer:</b><br><input type="text" value="2011-01-01" name="due_rev" size="15" maxlength="30" value="'.$row[8].'" /> <br>
<b>Due to SUSPO:</b><br><input type="text" name="due_suspo" size="15" maxlength="30" value="'.$row[9].'" /> <br>
<b>Due to Clerk:</b><br><input type="text" name="due_clerk" size="15" maxlength="30" value="'.$row[10].'" /> <br>
<b>Due to Attorney:</b><br><input type="text" name="due_attny" size="15" maxlength="30" value="'.$row[11].'" /> <br>
<b>Due to owner:</b><br><input type="text" name="due_owner" size="15" maxlength="30" value="'.$row[12].'" /> <br>

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

} else { 
	echo '<h1 id="mainhead">Page Error</h1>
	<p class="error">This page has been accessed in error.</p><p><br /><br /></p>';



Open in new window

Question by:wantabe2
    LVL 13

    Expert Comment

    The $nst variable isn't set before the update SQL.  Also post the error..
    LVL 15

    Accepted Solution

    I think you must post your update page edit_daq.php So it will be easy to see how your programming is working here you are posting the form only and you it is working.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Suggested Solutions

    As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
    Part of the Global Positioning System A geocode ( is the major subset of a GPS coordinate (, the other parts being the altitude and t…
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    734 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

    24 Experts available now in Live!

    Get 1:1 Help Now