PHP Code Help Needed!

I’ve attached a screenshot of my databse table as well as my code to this post for better clarification. Here’s my issue…The code I’ve posted works great. It will pull data from my DB & display it in a web browser form. On lines 177 through 187, this code is there I need the help. At this time the code between those lines pulls the names from the clerk_names table & randomly displays them in the “Automated Clerk Assignment” field. Each of the clerk names is set to active by the 1 in the active column. How can I edit this code so once the SQL pulls the name from the DB & displays it in my form, & then I submit it by clicking the “Place Assignments” button, the clerk name that is displayed in the form is set to a 0 in the active column?

SO basically, I just need the 1 to be updated to a 0 in the “active” column for the clerk name that is randomly displayed in the form. Thanks for any help!

[php]

To go to the main page click here.

<?php $page_title = 'Edit a Record'; $con = mysql_connect("localhost","uname","password"); 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 '

Page Error

This page has been accessed in error.



'; include ('./includes/footer.html'); exit(); } if (isset($_POST['submitted'])) { $errors = array(); if (empty($_POST['fname'])) { $errors[] = 'You forgot to enter the offenders first name.'; } else { $fn = $_POST['fname']; } if (empty($_POST['lname'])) { $errors[] = 'You forgot to enter the offenders last 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['item'])) { $errors[] = 'You forgot to enter a item number.'; } else { $dkt = $_POST['item']; } if (empty($_POST['mname'])) { $errors[] = 'You forgot to enter a middle name. If none, please enter NONE'; } else { $mn = $_POST['mname']; } if (empty($errors)) { $query = "UPDATE pinfo SET fname='$fn', lname='$ln', location='$loc', employee='$off', item='$dkt', mname='$mn' WHERE fid=$id"; $result = mysql_query($query); if (mysql_affected_rows() == 1) echo '

The assignment has been submitted successfully!

An email containing all this information has been sent to the assigned employee.

'; switch($_REQUEST['employee']) { case "John Doe": $Email = "[email protected]"; break; case "Jane Doe": $Email = "[email protected]"; break; case "Greg Johnson": $Email = "[email protected]"; break; default: echo "Error, no employee selected!!!"; break; } $Message = "Someone Has Been Assigned to You Below.\n \nName : ${_REQUEST['fname']} ${_REQUEST['mname']} ${_REQUEST['lname']} \nitem No : ${_REQUEST['item']} \nemployee : ${_REQUEST['employee']} \nLocation : ${_REQUEST['location']}"; $Subject = "Assignment"; $Headers = "From: [email protected] \n"; if (mail($Email, $Subject, $Message, $Headers)) exit(); } else { echo '

Error!

The following error(s) occurred:
'; foreach ($errors as $msg) { echo " - $msg
\n"; } echo '

If you continue to get this error call IT.


'; } } $query = "SELECT fname, lname, location, item, mname 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); ?> <?php

echo ’

This section assigns the it to an employee & a clerk. Your person will not be notified until the employee enters the information.

item No:

Location:

First Name:

Middle Name:

Last Name (Corporation/Partnership):

Assign To This employee:
John Doe Jane Doe Greg Johnson

';

} else { // Not a valid user ID.
echo ‘

Page Error


This page has been accessed in error.



’;
}

mysql_close(); // Close the database connection.

?>

<?php $mysqli = new mysqli('localhost', 'uname', 'password', 'flow'); $sql = "SELECT names FROM clerk_names WHERE active = '1' ORDER BY RAND() LIMIT 1"; $res = $mysqli->query($sql); $row = $res->fetch_row(); $randomName = $row[0]; $res->free(); ?> Automated Clerk Assignment:


[/php]

Ok, well…I’ve got the SQL that will update the ACTIVE field to a 0 but can not figure out how to insert this SQL into the above code to make it work just for the name that is randomly chosen from the DB. This SQL updates all the records to 0, & I need it to update just the name that is randomly chosen from the NAMES field…any suggestions?

Below is the code I have to update the active field to a 0:

[php]

<?php include('connection.php'); $update_0 = mysql_query( "SELECT clerk_id, names, active FROM clerk_names WHERE active = 1" ); if (mysql_errno()) { echo "MySQL error ".mysql_errno().": ".mysql_error()."\n
"; } while( $row = mysql_fetch_array( $update_0 ) ) { mysql_query( "UPDATE clerk_names SET active = 0 WHERE clerk_id = " . $row["clerk_id"] . " " ); } mysql_free_result( $update_0 ); ?>

[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service