[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

PHP & JavaScript Not Working

Posted on 2011-03-16
4
Medium Priority
?
226 Views
Last Modified: 2012-05-11
This code is supposed to pull data from a mysql database so I can edit it. that part works. The other part of this code is, it's supposed to send an email to an email address based off of the "location" field. If I choose "Office1, it will send the data to the mysql database as well as send an email to the email address in listed for office1 with the data that went to the mysql database.  Can someone take a look & correct my code issues?
<p> To go to the main page <a href="http://tnep-g-psrflow/flow/index.html">click here</a>.</p>


<?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);

//$result = mysql_query("SELECT * FROM psrinfo ");

// Check for a valid user ID, through GET or POST.
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();
}

// Check if the form has been submitted.

if (isset($_POST['submitted'])) {

	$errors = array(); // Initialize error 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['assgn_date'])) {
		$errors[] = 'You forgot to enter an assign date.';
	} else {
		$ad = $_POST['assgn_date'];
	}
	
	if (empty($_POST['interv_date'])) {
		$errors[] = 'You forgot to enter an interview date.';
	} else {
		$iv = $_POST['interv_date'];
	}
	
		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['employee'])) {
		$errors[] = 'You forgot to enter a employee.';
	} else {
		$off = $_POST['employee'];
	}
	
		if (empty($_POST['sent_date'])) {
		$errors[] = 'You forgot to enter a sentence date.';
	} else {
		$sd = $_POST['sent_date'];
	}
		if (empty($_POST['oth_date'])) {
		$errors[] = 'You forgot to enter an other date.';
	} else {
		$oth = $_POST['oth_date'];
	}
	
		if (empty($_POST['due_attny'])) {
		$errors[] = 'You forgot to enter an date.';
	} else {
		$atn = $_POST['due_attny'];
	}

	
	if (empty($errors)) { // If everything's OK.
	
		// Make the query.
		
		$query = "UPDATE psrinfo SET pacts='$pt', fname='$fn', lname='$ln', status='$st', location='$loc', employee='$off', sent_date='$sd', oth_date='$oth', assgn_date='$ad', interv_date='$iv', due_rev='$rv', due_suspo='$sus', due_clerk='$clk', due_attny='$atn', due_owner='$jdg'  WHERE fid=$id";
		//$query = "UPDATE psrinfo SET pacts='$pt', fname='$fn', lname='$ln', status='$st', location='$loc', assgn_date='$ad', interv_date='$iv', due_rev='$rv', due_suspo='$sus', due_clerk='$clk', due_attny='$atn', due_owner='$jdg', oth_date='$oth', employee='$off' WHERE fid=$id";

		$result = @mysql_query ($query); // Run the query.

$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, status, employee, location, assgn_date, interv_date, sent_date, oth_date, due_rev, due_suspo, due_clerk, due_attny, due_owner FROM psrinfo WHERE fid = " . $_REQUEST['id'];
$result = @mysql_query ($query); // Run the query.

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

	// Get the user's information.
	$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 a = form.assgn_date.value;
var s = form.sent_date.value;
var i = form.interv_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 assn  = new Date(a);
var sent = new Date(s);
var intv = new Date(i);
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);


if (isNaN(intv)) {
intv = new Date(assn.getFullYear(),assn.getMonth(),assn.getDate()+0);
}
if (isNaN(assn)) {
assn = new Date(assn.getFullYear(),assn.getMonth(),assn.getDate()+0);
}
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);
}


switch(due_rev.getDay()){
  case 0: due_rev.setDate(due_rev.getDate() - 1); // take one for Sunday
  case 6: due_rev.setDate(due_rev.getDate() - 1); // take two for Sunday or one for Saturday
}

switch(due_suspo.getDay()){
  case 0: due_suspo.setDate(due_suspo.getDate() - 1); // take one for Sunday
  case 6: due_suspo.setDate(due_suspo.getDate() - 1); // take two for Sunday or one for Saturday
}

switch(due_clerk.getDay()){
  case 0: due_clerk.setDate(due_clerk.getDate() - 1); // take one for Sunday
  case 6: due_clerk.setDate(due_clerk.getDate() - 1); // take two for Sunday or one for Saturday
}

switch(due_attny.getDay()){
  case 0: due_attny.setDate(due_attny.getDate() - 1); // take one for Sunday
  case 6: due_attny.setDate(due_attny.getDate() - 1); // take two for Sunday or one for Saturday
}

switch(due_owner.getDay()){
  case 0: due_owner.setDate(due_owner.getDate() - 1); // take one for Sunday
  case 6: due_owner.setDate(due_owner.getDate() - 1); // take two for Sunday or one for Saturday
}

switch(due_rev.getDay()){
  case 0: due_rev.setDate(due_rev.getDate() - 1); // take one for Sunday
  case 6: due_rev.setDate(due_rev.getDate() - 1); // take two for Sunday or one for Saturday
}

//form.assgn_date.value = (assn.getFullYear()+0) + "-" + d2(assn.getMonth()+1) + "-" + d2(assn.getDate());
//form.interv_date.value = (intv.getFullYear()+0) + "-" + d2(intv.getMonth()+1) + "-" + d2(intv.getDate());
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;
}

</script>
<?php


if (isset($_REQUEST['Submit'])) {  
# THIS CODE TELL MYSQL TO INSERT THE DATA FROM THE FORM INTO YOUR MYSQL TABLE  
$sql = "INSERT INTO $db_table(fname,lname,pacts,assgn_date,interv_date) values ('".mysql_real_escape_string(stripslashes($_REQUEST['fname']))."','".mysql_real_escape_string(stripslashes($_REQUEST['lname']))."','".mysql_real_escape_string(stripslashes($_REQUEST['pacts']))."','".mysql_real_escape_string(stripslashes($_REQUEST['assgn_date']))."','".mysql_real_escape_string(stripslashes($_REQUEST['interv_date']))."')"; 
if($result = mysql_query($sql ,$db)) { 



##################################################################### 
 
switch($_REQUEST['location']) { 
case "Office1":
$email = "office1@email.com";
break;
case "Office2":
$email = "office2@email.com";
break;
default:
echo "Error, no location selected!!!";
break; 
} 

$message = "<p>A date has changed. Please check the database</p><br> First Name: {$_REQUEST['fname']}<br>Last Name : {$_REQUEST['lname']}<br>PACTS No : {$_REQUEST['pacts']}<br>Date Assigned : {$_REQUEST['assgn_date']}<br>Date Interviewed : {$_REQUEST['interv_date']}<br>}";

 
 
$headers  = "MIME-Version: 1.0\n"; 
$headers .= "Content-type: text/html; charset=iso-8859-1\n"; 
$subject  = "Please Review the Changed Data";
$headers .= "To: DQA <$email>\n"; 
$headers .= "From: PODDS <sender email>\n"; 



 
if (mail($email, $subject, $message, $headers)) {

echo "<p><center><h2>The Office</h2></center></p>";
echo "<p><h3><center>Our Town</center></h3></p>";
echo "<center>An email has been sent to someone for editing and "; 
 
} else { 
 
echo "This system is not working properly. Please contact IT so he can fix it."; 
 
} 
 
 
 
 
 
########################################################################## 
















echo '<form action="edit_dqa.php" method="post">
<fieldset><legend><h1> You are editing a record!</h1></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>employee: </b><br><input type="text" name="employee" size="15" maxlength="30" value="'.$row[4].'" /> <br>

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

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

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


<b>Other Date:</b><br><input type="text" name="oth_date" size="15" maxlength="30" value="'.$row[9].'" /> <br>
<b>Assign Date:  </b><br><input type="text" name="assgn_date" size="15" maxlength="30" value="'.$row[6].'" /> <br>
<b>Interview Date:  </b><br><input type="text" name="interv_date" size="15" maxlength="30" value="'.$row[7].'" /> <br>
<b>Due to Reviewer:</b><br><input type="text" name="due_rev" size="15" maxlength="30" value="'.$row[10].'" /> <br>
<b>Due to SUSPO:</b><br><input type="text" name="due_suspo" size="15" maxlength="30" value="'.$row[11].'" /> <br>
<b>Due to Clerk:</b><br><input type="text" name="due_clerk" size="15" maxlength="30" value="'.$row[12].'" /> <br>
<b>Due to Attorney:</b><br><input type="text" name="due_attny" size="15" maxlength="30" value="'.$row[13].'" /> <br>
<b>Due to owner:</b><br><input type="text" name="due_owner" size="15" maxlength="30" value="'.$row[14].'" /> <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

0
Comment
Question by:wantabe2
  • 2
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
sihar86 earned 2000 total points
ID: 35152728
can you mention where is the error?
(both of javascript and php)
javascript error can see by Tools->Error Console->Error (if use mozilla firefox)
0
 
LVL 15

Author Comment

by:wantabe2
ID: 35155754
Thanks! At this time I am getting the following error:

Parse error: syntax error, unexpected $end in C:\wamp\www\flow\officer_query\edit_dqa.php on line 367

Line 367 is the very last line ?>

I'm a PHP newbee :)

Any help will be greatly appreciated.
0
 
LVL 15

Author Closing Comment

by:wantabe2
ID: 35156247
I used Mozzilla to figure it out.
0
 
LVL 2

Expert Comment

by:sihar86
ID: 35158195
try to check curly bracket.
Is all curly bracket have its pair?
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to implement server side field validation and display customized error messages to the client.
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses
Course of the Month18 days, 17 hours left to enroll

834 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