The Perfect Job (part 1) - Filing It All Away
(Page 11 of 11 )
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.| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |