Hi,
I'm new to PHP/SQL and am having trouble figuring out how to pass form-inputted variables across mulitple pages.
I am writing an application that allows a user to create/modify their companyProfile, add/modify/edit employeeProfile, and print various documents that contain all or some of the data contained in the multiple tables (MySQL database).
This particular piece of code:
- Creates a session for a user who logged into a Web site.
- When the user ADDS an employee to the database, it adds the record to the database (this works).
- I ask the user if they want to print the document. If they answer YES, then I want to pass all the newly entered form data to the next page that has the document with the company and employee's data. (I can get the company data based on the session, but I'm having trouble figuring out how to pass the employee data)
Any help is appreciated. Thanks!
<?php
session_start();
if ($_SESSION['valid_log'][0] != $_SERVER['REMOTE_ADDR'] ||
$_SESSION['valid_log'][1] != $_SESSION['User'])
{
//redirect to error page
echo '<META HTTP-EQUIV="Refresh" Content="1; URL=/error_access.html">';
exit();
}
<!-- Begin body -->
/* upon Submit : */
/* If plan type is family/single parent; change Dependents field to YES (default in Db is NO)*/
/* Add record to Db
/* Ask user if they want to print document now? */
/* If YES, pass employee variables to document */
/* If NO, redirect to master employee list */
// If plan type is family or single parent; change Dependents field to YES (default in Db is NO)
if (($HplanType=="SingleParent") || ($HplanType=="Family") || ($DplanType=="SingleParent") ||
($DplanType=="Family"))
{ $Dependents="Yes";
}
print "Dependents: $Dependents<br>";
print "$HplanType<br>";
// update Db
$link = mysql_connect("localhost", "root", "web2004") or die("Could not connect. Please try again later.");
mysql_select_db("ecbp",$link) or die("Could not select database. Please try again later.");
$sql5 = "INSERT INTO employeeProfile
(CompanyID, EmployeeFirst, EmployeeLast, EmployeeStreet1, EmployeeStreet2, EmployeeCity, EmployeeState, EmployeeZip, SpouseFirst, SpouseLast, Dependents, FSA, FSAamount, TAA, HealthPlan, HplanType, DentalPlan, DplanType)
VALUES('$CoID', '$EmployeeFirst', '$EmployeeLast', '$EmployeeStreet1', '$EmployeeStreet2', '$EmployeeCity', '$EmployeeState', '$EmployeeZip', '$SpouseFirst', '$SpouseLast', '$Dependents', '$FSA', '$AmountFSA', '$TAA', '$HealthPlan', '$HplanType', '$DentalPlan', '$DplanType')";
$result5 = mysql_query($sql5);
///////////////////////////////////////////////////////////////////////
/* THIS IS PART I'M HAVING TROUBLE WITH.
I tried the following but the AND statements corrupt the code (it doesn't work); if I remove AND statements and only use 1 WHERE clause, it results with an "Error with query 6"
// query the DB to get Employee ID that was just created
$query6 = "SELECT * FROM employeeProfile WHERE EmployeeLast=$EmployeeLast AND EmployeeFirst=$EmployeeFirst AND EmployeeZip=$EmployeeZip";
$result6 = mysql_query($query6) or die("Error with query 6.");
$row6 = mysql_fetch_array($result6);
if $row6 {
$EEid=$row6["EmployeeID"];
}
*/
// display confirmation and ask user if they want to print document
print "<p></p>";
echo '<b><FONT SIZE="4" COLOR="RED">The employee profile information was successfully added.<br><br>';
print "Do you want to Print their Initial COBRA Notice now?</FONT></b><br><br>";
echo '<b><FONT SIZE="4"><a href="f-A_initialnotice.php">YES</a> or <a href="employees.php">NO</a></FONT></b></p>';
?>
<!-- END of PHP/MYSQL code -->