Home arrow MySQL arrow Page 3 - The Perfect Job (part 2)

Adding To The Mix - MySQL

In the first part of this article, you built the architecturenecessary to accept and store resumes online. In this concluding part, findout how to make use of the stored data to find suitable candidates for aparticular job, and also read about the functions available to maintain andupdate the job listings.

TABLE OF CONTENTS:
  1. The Perfect Job (part 2)
  2. Administrator Ahoy!
  3. Adding To The Mix
  4. Changing Things Around
  5. Building Blocks
  6. Handling The Gray Areas
  7. Endgame
By: icarus, (c) Melonfire
Rating: starstarstarstarstar / 2
July 11, 2001

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
The script "add.php" display a form which allows an administrator to add a new job listing to the system. The script is divided into two sections - one section displays a form, while the other section processes the data entered into it. The $submit variable is used to decide which section of the script to execute.

<? // form not yet submitted if (!$submit) { // open connection to database $connection = mysql_connect($hostname, $user, $pass) or die ("Unable to connect!"); ?> <table border="0" cellspacing="5" cellpadding="2"> <form action="<? echo $PHP_SELF; ?>" method="POST"> <!-- input job details --> <tr> <td>Job code<font color="red">*</font></td> </tr> <tr> <td><input type="text" name="jcode" size="10" maxlength="10"></td> </tr> <tr> <td>Designation<font color="red">*</font></td> <td width=30> </td> <td>Department<font color="red">*</font></td> </tr> <tr> <td><input type="text" name="dsg" size="25"></td> <td width=30> </td> <td><select name="dpt"> <? // get department list $query = "SELECT id, department from department"; $result = mysql_db_query($database, $query, $connection) or die ("Error in query: $query. " . mysql_error()); while (list($id, $department) = mysql_fetch_row($result)) { echo "<option value=$id>$department</option>"; } mysql_free_result($result); ?> </select></td> </tr> <tr> <td>Location<font color="red">*</font></td> <td width=30> </td> <td>Salary<font color="red">*</font></td> </tr> <tr> <td><select name="loc"> <? // get location list $query = "SELECT id, location from location"; $result = mysql_db_query($database, $query, $connection) or die ("Error in query: $query. " . mysql_error()); while (list($id, $location) = mysql_fetch_row($result)) { echo "<option value=$id>$location</option>"; } mysql_free_result($result); ?> </select></td> <td width=30> </td> <td><select name="sal"> <? // get salary list $query = "SELECT id, salary from salary"; $result = mysql_db_query($database, $query, $connection) or die ("Error in query: $query. " . mysql_error()); while (list($id, $salary) = mysql_fetch_row($result)) { echo "<option value=$id>$salary</option>"; } mysql_free_result($result); mysql_close($connection); ?> </select></td> </tr> <tr> <td>Responsibilities<font color="red">*</font></td> <td width=30> </td> <td>Qualifications<font color="red">*</font></td> </tr> <tr> <td><textarea name="rsp" cols="40" rows="8"></textarea></td> <td width=30> </td> <td><textarea name="qlf" cols="40" rows="8"></textarea></td> </tr> <tr> <td>Contact person<font color="red">*</font></td> <td width=30> </td> <td>Email address<font color="red">*</font></td> </tr> <tr> <td><input type="text" name="cname" size="25"></td> <td width=30> </td> <td><input type="text" name="cmail" size="25"></td> </tr> <tr> <td align=center colspan=3><input type=submit name=submit value="Add Listing"></td> </tr> </table> </form> <? } else { // form submitted, process it } ?>
Here's what it looks like.



Nothing too complicated here - this is simply a form, with text fields for some elements of the job listing, and drop-down boxes for the remainder. You will notice that the items in the drop-downs are generated from the database; you probably remember this from last time.

Notice also the ACTION attribute of the <FORM> tag, which is pointing to a PHP variable called $PHP_SELF. This is a built-in PHP variable which always holds the name of the currently-executing script; by including it here, I am ensuring that the same script is also called to process the form.

Once the form is submitted, the same script is called again; however, since the $submit variable will now exist, the second half of the script springs into action.

<? <? // form not yet submitted if (!$submit) { // generate form } else { // form submitted, process it // set up error list array $errorList = array(); $count = 0; // validate text input fields if (empty($jcode)) { $errorList[$count] = "Invalid entry: Job code"; $count++; } if (empty($dsg)) { $errorList[$count] = "Invalid entry: Designation"; $count++; } if (empty($rsp)) { $errorList[$count] = "Invalid entry: Responsibilities"; $count++; } if (empty($qlf)) { $errorList[$count] = "Invalid entry: Qualifications"; $count++; } if (empty($cname)) { $errorList[$count] = "Invalid entry: Contact name"; $count++; } if (empty($cmail) || isEmailInvalid($cmail)) { $errorList[$count] = "Invalid entry: Email address"; $count++; } if (sizeof($errorList) == 0) { // open connection to database $connection = mysql_connect($hostname, $user, $pass) or die ("Unable to connect!"); // insert data $query = "INSERT INTO listing (jcode, designation, responsibilities, qualifications, cname, cmail, posted, fk_department, fk_location, fk_salary) VALUES ('$jcode', '$dsg', '$rsp', '$qlf', '$cname', '$cmail', NOW(), '$dpt', '$loc', '$sal')"; $result = mysql_db_query($database, $query, $connection) or die ("Error in query: $query. " . mysql_error()); // clean up mysql_close($connection); echo "Entry successfully added.<p><a href=$PHP_SELF>Add another entry</a>, or <a href=job_list.php>return to job listings</a>"; } else { listErrors(); } } ?>
The error-checking mechanism used here should be familiar to you from the job application form in the previous article...although the validation routines here are a little simpler, since this form is far less complex.

Once the data has been validated and found to be acceptable, an INSERT query takes care of saving the data to the "listing" table, so that it immediately appears on the job listing page.

This article copyright Melonfire 2001. All rights reserved.

 
 
>>> More MySQL Articles          >>> More By icarus, (c) Melonfire
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

MYSQL ARTICLES

- Oracle Unveils MySQL 5.6
- MySQL Vulnerabilities Threaten Databases
- MySQL Cloud Options Expand with Google Cloud...
- MySQL 5.6 Prepped to Handle Demanding Web Use
- ScaleBase Service Virtualizes MySQL Databases
- Oracle Unveils MySQL Conversion Tools
- Akiban Opens Database Software for MySQL Use...
- Oracle Fixes MySQL Bug
- MySQL Databases Vulnerable to Password Hack
- MySQL: Overview of the ALTER TABLE Statement
- MySQL: How to Use the GRANT Statement
- MySQL: Creating, Listing, and Removing Datab...
- MySQL: Create, Show, and Describe Database T...
- MySQL Data and Table Types
- McAfee Releases Audit Plugin for MySQL Users

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: