perrij3 Posted August 4, 2009 Share Posted August 4, 2009 I am working on creating a website for a funeral home. I need to be able to add an obituary entry which contains information about the person. visitation details and service location. I have created my MySQL database for these tables as such: [u]Individual[/u] (Table 1) `OB_ID` SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT , `FirstName` VARCHAR( 50 ) NOT NULL , `MiddleName` VARCHAR( 50 ) NULL , `LastName` VARCHAR( 50 ) NOT NULL , `SurName` VARCHAR( 5 ) NULL , `DateBorn` DATE NULL , `DatePassed` DATE NULL , `Obituary` TEXT NULL , `DateEntered` TIMESTAMP NOT NULL, PRIMARY KEY ( `OB_ID` ) ) ENGINE = InnoDB [u]Visitation_Locale[/u] (Table 2) `VisitLoc_ID` SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT , `Name` VARCHAR( 100 ) NOT NULL , `Address1` VARCHAR( 100 ) NOT NULL , `Address2` VARCHAR( 100 ) NULL , `City` VARCHAR( 50 ) NOT NULL , `State` CHAR( 2 ) NOT NULL , `Zip` CHAR( 10 ) NOT NULL , PRIMARY KEY ( `VisitLoc_ID` ) ) ENGINE = InnoDB [u]Service[/u] (Table 3) `Service_ID` SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT , `Name` VARCHAR( 100 ) NOT NULL , `Address1` VARCHAR( 100 ) NOT NULL , `Address2` VARCHAR( 100 ) NULL , `City` VARCHAR( 50 ) NOT NULL , `State` CHAR( 2 ) NOT NULL , `Zip` CHAR( 10 ) NOT NULL , PRIMARY KEY ( `Service_ID` ) ) ENGINE = InnoDB [u]Individual_Service[/u] (Table 4) `FK_OB_ID` SMALLINT NOT NULL , `FK_Service_ID` SMALLINT NOT NULL , `StartTime` VARCHAR( 8 ) NOT NULL , `EndTime` VARCHAR( 8 ) NOT NULL , `Date` DATE NOT NULL , PRIMARY KEY ( `FK_OB_ID` , `FK_Service_ID` ) ) ENGINE = InnoDB [u]Individual_Visitations[/u] (Table 5) `Visit_ID` SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT , `FK_OB_ID` SMALLINT NOT NULL , `FK_VisitLoc_ID` SMALLINT NOT NULL , `StartTime` VARCHAR( 8 ) NOT NULL , `EndTime` VARCHAR( 8 ) NOT NULL , `Date` DATE NOT NULL , PRIMARY KEY ( `Visit_ID` ) ) ENGINE = InnoDB What I am trying to do is create 3 forms that go like this. First the user enters the information for the obituary, then the user enters information about the visitation (a person can have more than 1 visitation), after that a form to select where the service will be at. The reason for this is each visitation and service will have a different day and time, so I figured this would be the easiest way for the user to enter all the data into the database. The problem I am having is with passing the obituary ID (OB_ID) to the next form. Everything is tied to that number. I don't know if my thinking is correct on this or not, but this is how I image it should work. The user enters the information into the first form, presses submit. The php file that I am using to post this information into the database some how receives the new (OB_ID) number it created and passes it onto the next form (visitation). Am I headed in the right direction or is my thinking way off? I did read somewhere about the storing a user ID variable that is generated when someone submits data by using a session variable. I tried to set one up in this code, but it doesn't seem to work or I just am not sure how to retrieve it on the next page. Here is the code that I am using to <?php // clear any existing session variables $_SESSION = array(); // set a variable to control access to other pages $_SESSION['ObituaryInfo'] = true; $required = array('user_id'); include('../includes/connection.inc.php'); include('../includes/corefuncs.php'); if (array_key_exists('insert', $_POST)) { //change birth date to MqSQL format $bm = $_POST['birthmonth']; $bd = trim($_POST['birthday']); $by = trim($_POST['birthyear']); if (empty($bd) || empty($by)) { $error = 'Please fill in all birth date fields'; } elseif (!is_numeric($bd) || !is_numeric($by)) { $error = 'Please use numbers only'; } elseif (($bd < 1 || $bd > 31) || ($by < 1890 || $by > 2100)) { $error = 'Please use numbers within the correct date or year range in birth date.'; } elseif (!checkdate($bm,$bd,$by)) { $error = 'You have used an invalid birth date'; } else { $bd = $bd < 10 ? '0'.$bd : $bd; $DateBorn = "$by-$bm-$bd"; } //change passed date to MqSQL format $pm = $_POST['passedmonth']; $pd = trim($_POST['passedday']); $py = trim($_POST['passedyear']); if (empty($pd) || empty($py)) { $error = 'Please fill in all passed date fields'; } elseif (!is_numeric($pd) || !is_numeric($py)) { $error = 'Please use numbers only'; } elseif (($pd < 1 || $pd > 31) || ($py < 1000 || $py > 99999)) { $error = 'Please use numbers within the correct date or year range for the passing date.'; } elseif (!checkdate($pm,$pd,$py)) { $error = 'You have used an invalid passing date.'; } else { $pd = $pd < 10 ? '0'.$pd : $pd; $DatePassed = "$py-$pm-$pd"; } //Remove backslashes nukeMagicQuotes(); //prepare an array of expected items $expected = array('FirstName', 'MiddleName', 'LastName', 'SurName', 'DateBorn', 'DatePassed', 'Obituary', 'DateEntered'); //create database connection $conn = dbConnect(''); //make $_POST data safe for insertion into database foreach ($_POST as $key => $value) { if (in_array($key, $expected)) { ${$key} = mysql_real_escape_string($value); } } //prepare the SQL query $sql = "INSERT INTO obituaries (`FirstName`, `MiddleName`, `LastName`, `SurName`, `DateBorn`, `DatePassed`, `Obituary`, `DateEntered`) VALUES('$FirstName', '$MiddleName', '$LastName', '$SurName', '$DateBorn', '$DatePassed', '$Obituary', NOW())"; //process the query $result = mysql_query($sql) or die(mysql_error()); //store Person Obituary ID $user_id = mysql_insert_id( $conn ); //if successful, redirect to Vistitation form. if ($result) { header('Location: http://localhost/funeralhome/admin/add_ob_visitation.php'); exit; } } ?> Thank you for any help or suggestions you can provide. Link to comment https://forums.phpfreaks.com/topic/168799-multiple-forms/ Share on other sites More sharing options...
jonsjava Posted August 4, 2009 Share Posted August 4, 2009 you forgot to start the session. <?php session_start(); // clear any existing session variables // set a variable to control access to other pages $_SESSION['ObituaryInfo'] = true; $required = array('user_id'); include('../includes/connection.inc.php'); include('../includes/corefuncs.php'); if (array_key_exists('insert', $_POST)) { //change birth date to MqSQL format $bm = $_POST['birthmonth']; $bd = trim($_POST['birthday']); $by = trim($_POST['birthyear']); if (empty($bd) || empty($by)) { $error = 'Please fill in all birth date fields'; } elseif (!is_numeric($bd) || !is_numeric($by)) { $error = 'Please use numbers only'; } elseif (($bd < 1 || $bd > 31) || ($by < 1890 || $by > 2100)) { $error = 'Please use numbers within the correct date or year range in birth date.'; } elseif (!checkdate($bm,$bd,$by)) { $error = 'You have used an invalid birth date'; } else { $bd = $bd < 10 ? '0'.$bd : $bd; $DateBorn = "$by-$bm-$bd"; } //change passed date to MqSQL format $pm = $_POST['passedmonth']; $pd = trim($_POST['passedday']); $py = trim($_POST['passedyear']); if (empty($pd) || empty($py)) { $error = 'Please fill in all passed date fields'; } elseif (!is_numeric($pd) || !is_numeric($py)) { $error = 'Please use numbers only'; } elseif (($pd < 1 || $pd > 31) || ($py < 1000 || $py > 99999)) { $error = 'Please use numbers within the correct date or year range for the passing date.'; } elseif (!checkdate($pm,$pd,$py)) { $error = 'You have used an invalid passing date.'; } else { $pd = $pd < 10 ? '0'.$pd : $pd; $DatePassed = "$py-$pm-$pd"; } //Remove backslashes nukeMagicQuotes(); //prepare an array of expected items $expected = array('FirstName', 'MiddleName', 'LastName', 'SurName', 'DateBorn', 'DatePassed', 'Obituary', 'DateEntered'); //create database connection $conn = dbConnect(''); //make $_POST data safe for insertion into database foreach ($_POST as $key => $value) { if (in_array($key, $expected)) { ${$key} = mysql_real_escape_string($value); } } //prepare the SQL query $sql = "INSERT INTO obituaries (`FirstName`, `MiddleName`, `LastName`, `SurName`, `DateBorn`, `DatePassed`, `Obituary`, `DateEntered`) VALUES('$FirstName', '$MiddleName', '$LastName', '$SurName', '$DateBorn', '$DatePassed', '$Obituary', NOW())"; //process the query $result = mysql_query($sql) or die(mysql_error()); //store Person Obituary ID $user_id = mysql_insert_id( $conn ); //if successful, redirect to Vistitation form. if ($result) { header('Location: http://localhost/funeralhome/admin/add_ob_visitation.php'); exit; } } ?> Link to comment https://forums.phpfreaks.com/topic/168799-multiple-forms/#findComment-890554 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.