Having a problem with this form. What I need is for it to grab the user_id via the user_name entered (from the user table), the sect_id from the section entered (from the section table) and the staff_id from the staff name entered (from the staff table). The user_id, sect_id, staff_id and added choice will go into its on table called regist (reg_id, user_id, staff_id, regist). Is this even possbile before I try it? Staff ID is carried over via sessions.
Here is my basic handler for the form:
[B]// Adding this as all staff members must be logged in to even view this form[/B]
if (!isset($_SESSION['staff_id'])) {
header ("Location: [url]http://[/url]" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/index.php");
ob_end_clean();
exit();
} else {
if(isset($_POST['submit'])){// handle the form
// Connect to the database.
require_once ('incl/mysql_connect.php');
// Query the database.
[B]// Think I would query the fields here?[/B]
$query = "SELECT user_id , staff_id, sect_id FROM user, staff, section WHERE user_name='$user_name' AND section='$section' AND staff_name='$staff_name'";
$result = @mysql_query ($query);
// The insert condition.
$query = "INSERT INTO regist (user_id, staff_id, sect_id, regist) VALUES ('$user_id', '$staff_id', '$sect_id', '$regist')";
$result = @mysql_query ($query); // Run the query.
if ($result) { // If it ran OK.
// Send an email, if desired.
echo '<p class=content>Thank you for adding this registration!</p>';
exit();
} else { // If it did not run OK.
// Send a message to the error log, if desired.
echo '<p class=content>Your information could not be registered due to a system error. We apologize for any inconvenience.</p>';
}
mysql_close(); // Close the database connection.
} // End of the main Submit conditional.
Here is the form:
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p align="justify">User Name:<br/><input class="title" type="text" name="user_name" size="50" maxlength="50" value="<?php if (isset($POST['user_name'])) echo $POST['user_name']; ?>" /></p>
<p align="justify" valign=top>Registration Type:<br/> <SELECT NAME="section" class=title>
<option value="Choice 1">Choice 1</option>
<option value="Choice 2">Choice 2</option>
<option value="Choice 3" selected>Choice 3</option>
<option value="Choice 4">Choice 4</option>
<option value="Choice 5">Choice 5</option>
<option value="Choice 6">Choice 6</option>
</SELECT>
</p>
<p align="justify">Registration #:<br/><input class="title" type="text" name="regist" size="25" maxlength="25" value="<?php if (isset($POST['regist'])) echo $POST['regist']; ?>" /></p>
<p align="justify">Staff Name:<br/><input class="title" type="text" name="staff_name" size="25" maxlength="25" value="<?php if (isset($POST['staff_name'])) echo $POST['staff_name']; ?>" /></p>
<div align="center"><input class="head" type="submit" name="submit" value="Submit Reg" /></div>
</form><!-- End of Form -->