Recruitment - the art of matching qualified applications to openpositions within an organization - is one of the most challenging tasks forany Human Resources department. However, powerful open-source tools likePHP and mySQL have made the process simpler, more efficient and moreeconomical than at any time in the past. This case study demonstrates how,by building a complete job listing and resume management system fromscratch.
At the end of all the validation, the size of the $errorList array is checked. If the size is 0, it implies that no errors were detected, and database insertion begins.
<?
// no errors
if (sizeof($errorList) == 0)
{
// insert personal info
$query = "INSERT INTO r_user (jcode, fname, lname, dob, addr1, addr2,
city, state, zip, fk_country, phone, email, url, relo, posted) VALUES
('$jcode', '$fname', '$lname', '$dob', '$addr1', '$addr2', '$city',
'$state', '$zip', '$country', '$phone', '$email', '$url', '$relo',
NOW(''))";
$result = mysql_db_query($database, $query, $connection) or die ("Error in
query: $query. " . mysql_error());
// get resume id, for use in subsequent operations
$rid = mysql_insert_id($connection);
// insert educational qualifications
for($x=0; $x<sizeof($institute); $x++)
{
if (!empty($institute[$x]) && !empty($degree_year[$x]))
{
$query = "INSERT INTO r_education (rid, institute, fk_degree,
fk_subject, year) VALUES ('$rid', '$institute[$x]', '$degree[$x]',
'$subject[$x]', '$degree_year[$x]')";
$result = mysql_db_query($database, $query, $connection) or
die ("Error in query: $query. " . mysql_error());
}
}
// and so on
// print success code
echo "Your application has been accepted.<p><a href=job_list.php>
Return to job listings</a>";
}
else
{
// or list errors
listErrors();
}
?>
If error messages are present, the listErrors() function is called to
display a list of error messages. No database insertion takes place, and the user has the option to return to the previous page to rectify the errors.
<?
// produce a list of errors after validating a form
function listErrors()
{
// read the errorList array
global $errorList;
// print as list
echo "The following errors were encountered: <br>";
echo "<ul>";
for ($x=0; $x<sizeof($errorList); $x++)
{
echo "<li>$errorList[$x]";
}
echo "</ul>";
// link to go back and correct errors
echo "Click <a href=javascript:history.back();>here</a> to go back to the
previous page and correct the errors";
}
?>
At this point, all relevant user information has been stored in the
various database tables. This is the end of the user process flow; the focus now shifts to data retrieval and maintenance, both of which are exclusively administrative functions.
In the second part of this article, I'll examine the administration scripts related to adding, editing and deleting job listings, together with a look at a basic search engine to sift through all the data. In the meanwhile, download the code, play with it, send me your thoughts/flames/savings...and come back next time for more!
This article copyright Melonfire 2001. All rights reserved.