Solved

PHP Code Not Updating Database

Posted on 2013-01-15
3
239 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 27

Expert Comment

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

Accepted Solution

by:
Lukasz Chmielewski earned 500 total points
ID: 38779548
<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
ID: 38779649
That was it & thanks again friend!
0

Featured Post

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
This article discusses how to implement server side field validation and display customized error messages to the client.
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 …
The viewer will learn how to dynamically set the form action using jQuery.

707 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