PHP Code Issue

The attached code pulls data from my MySQL database & displays it in a browser & it works great but I need it to do one more thing & I can’t figure out a way to make it work & ask for your help. If you look at lines 177 - 187, this is where I need the assistance. At this time these lines of code pull the NAMES from the CLERK_NAMES table WHERE the ACTIVE field is set to 1.

Here is what I need help with…once the user clicks the “Place Assignments” button, I need for the ACTIVE field to be updated to a 0…can anyone help me with this? Thanks

[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]

This fixed it:

[php]

<?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); $res->free(); ?>

[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service