Solved

PHP Code Not Updating Database

Posted on 2013-01-15
3
232 Views
Last Modified: 2013-01-15
This code pulls data from my MySQL database & displays it in a form. Then a user will choose an employee from the drop down box on line 165, choose submit & that employee & the clerk that is randomly inserted on line 219 get an email. For some reason my code is not updating the MySQL databse for the clerk name that is randomly inserted on line 219. When I do submit it, it get the error on line 74. Can I get a second pair of eyes to look at it to see why? Thanks

<p> <b> <i>To go to the main page <a href="http://16.12.5.24/gflow/index.html">click here</a>.</b> </i></p>

<html>  
<body bgcolor=""> 
<head> 

<?php

$page_title = 'Edit a Record';

$con = mysql_connect("localhost","uname","pword");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("flow", $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 { // 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();
}

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

	$errors = array();
	
	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 olast name.';
	} else {
		$ln = $_POST['lname'];
	}
		
		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['dnumber'])) {
		$errors[] = 'You forgot to enter a dnumber number.';
	} else {
		$dkt = $_POST['dnumber'];
	}
	
			if (empty($_POST['mname'])) {
		$errors[] = 'You forgot to enter a middle name. If none, please enter NONE';
	} else {
		$mn = $_POST['mname'];
	}
		
			if (empty($_POST['clerk'])) {
		$errors[] = 'You forgot to enter a clerk';
	} else {
		$wo = $_POST['clerk'];
	}
		
	if (empty($errors)) { 
	
	$query = "UPDATE psrinfo SET fname='$fn', lname='$ln', location='$loc', employee='$off', dnumber='$dkt', mname='$mn', clerk='$wo' WHERE fid=$id";
	$result = mysql_query($query);
	
			if (mysql_affected_rows() == 1)
	echo '<p><b><center>The assignment has been submitted successfully! </p><p>An email containing all this information has been sent to the assigned employee.</b></p></center>';
				
switch($_REQUEST['employee']) { 
case "employee1":
$Email = "myemail@yahoo.com";
break;
case "employee2":
$Email = "myemail@yahoo.com";
break;
case "employee3":
$Email = "myemail@yahoo.com";
break;
default:
echo "Error, no employee selected!!!";
break; 
}

switch($_REQUEST['clerk']) { 
case "Clerk1":
$Email2 = "myemail@yahoo.com";
break;
case "clerk2":
$Email2 = "myemail@yahoo.com";
break;
case "clerk3":
$Email2 = "myemail@yahoo.com";
break;
default:
echo "Error, no clerk selected!!!";
break; 
}

$Message = "A customer Has Been Assigned to You Below.\n \nOffender Name : ${_REQUEST['fname']} ${_REQUEST['mname']} ${_REQUEST['lname']} \ndnumber No : ${_REQUEST['dnumber']} \nemployee : ${_REQUEST['employee']} \nLocation : ${_REQUEST['location']} \nClerk : ${_REQUEST['clerk']}";
$Subject  = "Assignment";
$Headers = "From: PDS@myemail.com \n"; 

 	if (mail($Email, Email2, $Subject, $Message, $Headers)) 
						
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>If you continue to get this error call someone.</b></p><p><br /></p>';
		
	} 

} 

$query = "SELECT fname, lname, location, dnumber, mname, clerk FROM info WHERE fid = " . $_REQUEST['id'];
$result = @mysql_query ($query); // Run the query.

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

	$row = mysql_fetch_array ($result, MYSQL_NUM);
		
?>	
<body style="background-image:url(FadedBG.png); background-repeat:no-repeat; background-attachment:fixed; background-position:center;">
<?php

echo '<form action="help.php" method="post">
<legend><h3> This section assigns the person to an employee & a clerk. You will not be notified until the employee enters the information.</h2></legend>

<table width="95%" border="1">
<tr>
<td><b>dnumber No:</b> <br><input type="text" name="dnumber" size="15" maxlength="30" value="'.$row[3].'" /><br> </td>
<td><b>Sent Location: </b><br><input type="text" name="location" size="15" maxlength="30" value="'.$row[2].'" /><br></td>
</tr>

<tr>
<td><b>First Name:</b> <br><input type="text" name="fname" size="15" maxlength="30" value="'.$row[0].'" /><br /> </td>
<td><b>Middle Name:</b> <br><input type="text" name="mname" size="15" maxlength="30" value="'.$row[4].'" /><br /> </td>
<td><b>Last Name:</b> <br><input type="text" name="lname" size="25" maxlength="30" value="'.$row[1].'" /><br /> </td>
</tr>

<td>
<b>Assign To This employee:<br> 
<select name="employee"> 
<option value=""></option>
<option value="Employee1">Employee1</option>
<option value="Employee2">Employee2</option>
<option value="Employee3">Employee3</option>

</select> 
</td>

</tr>

</tr>

</table>

<br>

<div align="left"><input type="submit" name="submit" value="Place Assignments" /></div>

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

?>

<?php
$mysqli = new mysqli('localhost', 'uname', 'pword', 'flow'); 
$sql = "SELECT names, active, clerk_id FROM clerk_names WHERE active = '1' ORDER BY RAND() LIMIT 1";
$res = $mysqli->query($sql); 
$row = $res->fetch_row(); 
$randomName = $row[0];  
$res->free(); 
$sql = "UPDATE clerk_names SET active = 0 WHERE clerk_id = " . $row[2] . " " ;
$res = $mysqli->query($sql); 

} 

{

 $sql = "SELECT count(clerk_id) FROM clerk_names WHERE active = 0";
 $res = $mysqli->query($sql); 
 $row = $res->fetch_row(); 
 $numzeros = $row[0];  
 $res->free(); 

 if($numzeros == 10){
   $sql = "UPDATE clerk_names SET active = 1" ;             
   $res = $mysqli->query($sql);
 }
}
mysql_close(); // Close the database connection.
?> 

<td><b>Automated Clerk Assignment:</b> <br><input type="text" name="clerk" size="21" maxlength="40" value="<?php echo $randomName;?>" /><br /> </td>

Open in new window

0
Comment
Question by:wantabe2
  • 2
3 Comments
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
move your
</form>';
down to bottom of the script
0
 
LVL 27

Accepted Solution

by:
Lukasz Chmielewski earned 500 total points
Comment Utility
<p> <b> <i>To go to the main page <a href="http://16.12.5.24/gflow/index.html">click here</a>.</b> </i></p>

<html>  
<body bgcolor=""> 
<head> 

<?php

$page_title = 'Edit a Record';

$con = mysql_connect("localhost","uname","pword");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("flow", $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 { // 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();
}

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

	$errors = array();
	
	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 olast name.';
	} else {
		$ln = $_POST['lname'];
	}
		
		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['dnumber'])) {
		$errors[] = 'You forgot to enter a dnumber number.';
	} else {
		$dkt = $_POST['dnumber'];
	}
	
			if (empty($_POST['mname'])) {
		$errors[] = 'You forgot to enter a middle name. If none, please enter NONE';
	} else {
		$mn = $_POST['mname'];
	}
		
			if (empty($_POST['clerk'])) {
		$errors[] = 'You forgot to enter a clerk';
	} else {
		$wo = $_POST['clerk'];
	}
		
	if (empty($errors)) { 
	
	$query = "UPDATE psrinfo SET fname='$fn', lname='$ln', location='$loc', employee='$off', dnumber='$dkt', mname='$mn', clerk='$wo' WHERE fid=$id";
	$result = mysql_query($query);
	
			if (mysql_affected_rows() == 1)
	echo '<p><b><center>The assignment has been submitted successfully! </p><p>An email containing all this information has been sent to the assigned employee.</b></p></center>';
				
switch($_REQUEST['employee']) { 
case "employee1":
$Email = "myemail@yahoo.com";
break;
case "employee2":
$Email = "myemail@yahoo.com";
break;
case "employee3":
$Email = "myemail@yahoo.com";
break;
default:
echo "Error, no employee selected!!!";
break; 
}

switch($_REQUEST['clerk']) { 
case "Clerk1":
$Email2 = "myemail@yahoo.com";
break;
case "clerk2":
$Email2 = "myemail@yahoo.com";
break;
case "clerk3":
$Email2 = "myemail@yahoo.com";
break;
default:
echo "Error, no clerk selected!!!";
break; 
}

$Message = "A customer Has Been Assigned to You Below.\n \nOffender Name : ${_REQUEST['fname']} ${_REQUEST['mname']} ${_REQUEST['lname']} \ndnumber No : ${_REQUEST['dnumber']} \nemployee : ${_REQUEST['employee']} \nLocation : ${_REQUEST['location']} \nClerk : ${_REQUEST['clerk']}";
$Subject  = "Assignment";
$Headers = "From: PDS@myemail.com \n"; 

 	if (mail($Email, Email2, $Subject, $Message, $Headers)) 
						
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>If you continue to get this error call someone.</b></p><p><br /></p>';
		
	} 

} 

$query = "SELECT fname, lname, location, dnumber, mname, clerk FROM info WHERE fid = " . $_REQUEST['id'];
$result = @mysql_query ($query); // Run the query.

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

	$row = mysql_fetch_array ($result, MYSQL_NUM);
		
?>	
<body style="background-image:url(FadedBG.png); background-repeat:no-repeat; background-attachment:fixed; background-position:center;">
<?php

echo '<form action="help.php" method="post">
<legend><h3> This section assigns the person to an employee & a clerk. You will not be notified until the employee enters the information.</h2></legend>

<table width="95%" border="1">
<tr>
<td><b>dnumber No:</b> <br><input type="text" name="dnumber" size="15" maxlength="30" value="'.$row[3].'" /><br> </td>
<td><b>Sent Location: </b><br><input type="text" name="location" size="15" maxlength="30" value="'.$row[2].'" /><br></td>
</tr>

<tr>
<td><b>First Name:</b> <br><input type="text" name="fname" size="15" maxlength="30" value="'.$row[0].'" /><br /> </td>
<td><b>Middle Name:</b> <br><input type="text" name="mname" size="15" maxlength="30" value="'.$row[4].'" /><br /> </td>
<td><b>Last Name:</b> <br><input type="text" name="lname" size="25" maxlength="30" value="'.$row[1].'" /><br /> </td>
</tr>

<td>
<b>Assign To This employee:<br> 
<select name="employee"> 
<option value=""></option>
<option value="Employee1">Employee1</option>
<option value="Employee2">Employee2</option>
<option value="Employee3">Employee3</option>

</select> 
</td>

</tr>

</tr>

</table>

<br>

<div align="left"><input type="submit" name="submit" value="Place Assignments" /></div>

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

<?php
$mysqli = new mysqli('localhost', 'uname', 'pword', 'flow'); 
$sql = "SELECT names, active, clerk_id FROM clerk_names WHERE active = '1' ORDER BY RAND() LIMIT 1";
$res = $mysqli->query($sql); 
$row = $res->fetch_row(); 
$randomName = $row[0];  
$res->free(); 
$sql = "UPDATE clerk_names SET active = 0 WHERE clerk_id = " . $row[2] . " " ;
$res = $mysqli->query($sql); 

} 

{

 $sql = "SELECT count(clerk_id) FROM clerk_names WHERE active = 0";
 $res = $mysqli->query($sql); 
 $row = $res->fetch_row(); 
 $numzeros = $row[0];  
 $res->free(); 

 if($numzeros == 10){
   $sql = "UPDATE clerk_names SET active = 1" ;             
   $res = $mysqli->query($sql);
 }
}
mysql_close(); // Close the database connection.
?> 

<td><b>Automated Clerk Assignment:</b> <br><input type="text" name="clerk" size="21" maxlength="40" value="<?php echo $randomName;?>" /><br /> </td>
<?php echo '</form>';?>

Open in new window

0
 
LVL 15

Author Closing Comment

by:wantabe2
Comment Utility
That was it & thanks again friend!
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Creating and Managing Databases with phpMyAdmin in cPanel.
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

743 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

18 Experts available now in Live!

Get 1:1 Help Now