?
Solved

PHP Code Not Updating Database

Posted on 2013-01-15
3
Medium Priority
?
242 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 2000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

762 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