goldenbrown21 Posted June 29, 2008 Share Posted June 29, 2008 Hi All, First of all, apologies on the lengthy code. It's a detailed form. I have the below code with is my form. Currently, I have a session which identify's whether the user has logged in successfully. My issue is that I want to run another session which stores the entered form data temporarily. This form goes to a validation page which asks the user to go back and make any changes if they caused an error, otherwise, the form information gets stored in a mysql database. If you can advise or provide a example, it would be greatly appreciated. <?php session_start(); $MM_authorizedUsers = ""; $MM_donotCheckaccess = "true"; // *** Restrict Access To Page: Grant or deny access to this page function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { // For security, start by assuming the visitor is NOT authorized. $isValid = False; // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. // Therefore, we know that a user is NOT logged in if that Session variable is blank. if (!empty($UserName)) { // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. // Parse the strings into arrays. $arrUsers = Explode(",", $strUsers); $arrGroups = Explode(",", $strGroups); if (in_array($UserName, $arrUsers)) { $isValid = true; } // Or, you may restrict access to only certain users based on their username. if (in_array($UserGroup, $arrGroups)) { $isValid = true; } if (($strUsers == "") && true) { $isValid = true; } } return $isValid; } $MM_restrictGoTo = "login.php"; if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) { $MM_qsChar = "?"; $MM_referrer = $_SERVER['PHP_SELF']; if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&"; if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0) $MM_referrer .= "?" . $QUERY_STRING; $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer); header("Location: ". $MM_restrictGoTo); exit; } ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>NSC - Input Customer Data</title> <style type="text/css"> body,td,th { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; color: #000000; } body { background-color: #666666; background-image: url(images/background.jpg); } .style1 { color: #FF0000; font-weight: bold; } .style2 {color: #FF0000} .style3 { font-size: 24px; font-weight: bold; } </style></head> <body> <form action="input.php" method="POST" name="InputCustomer" id="InputCustomer"> <div align="center"> <p><span class="style3">Input Your Customer Details </span></p> <table width="800" border="0" align="center" cellpadding="0" cellspacing="3"> <tr> <td valign="bottom"><table width="400" border="0" align="left" cellpadding="5" cellspacing="0"> <tr> <td><div align="right" class="style1">CustCode:</div></td> <td><div align="left"> <input name="CustCode" type="text" id="CustCode" size="10" maxlength="10"> </div></td> <td><div align="right" class="style1">CustName:</div></td> <td><div align="right"></div></td> <td colspan="2"><div align="left"> <input name="CustName" type="text" id="CustName" size="40"> </div></td> </tr> <tr> <td><div align="right" class="style1">Street Address:</div></td> <td colspan="5"><div align="left"> <input name="StreetAddress" type="text" id="StreetAddress" size="50"> </div></td> </tr> <tr> <td height="58"><div align="right" class="style1">Suburb:</div></td> <td colspan="2"><div align="left"> <input name="Suburb" type="text" id="Suburb" size="30"> </div></td> <td><div align="center"></div></td> <td><div align="right" class="style1">State: </div></td> <td><select name="State" size="1" id="State"> <option value="VIC">VIC</option> <option value="NSW">NSW</option> <option value="QLD">QLD</option> <option value="WA">WA</option> <option value="NT">NT</option> <option value="SA">SA</option> <option value="ACT">ACT</option> <option value="TAS">TAS</option> </select></td> </tr> </table></td> <td rowspan="2" valign="top"><table width="400" border="0" align="center" cellpadding="5" cellspacing="2"> <tr> <td width="163"><div align="right" class="style1">Trading Patterns </div></td> <td width="163"><div align="left"> <select name="TradingPattern" size="1" id="TradingPattern"> <option value="Regular">Regular</option> <option value="Irregular">Irregular</option> </select> </div></td> <td width="51"><div align="right" class="style1">MTD</div></td> <td width="130"><input name="MTD" type="text" id="MTD" size="3" maxlength="3"></td> </tr> <tr> <td><div align="right" class="style1">Payment Type </div></td> <td><div align="left"> <select name="PaymentType" size="1" id="PaymentType"> <option value="CBD">CBD</option> <option value="COD">COD</option> <option value="Terms 7 Days">Terms 7 Days</option> <option value="Terms 14 Days">Terms 14 Days</option> <option value="Terms 30 Days">Terms 30 Days</option> </select> </div></td> <td><p align="right" class="style1">Last Month</p></td> <td><input name="LastMonth" type="text" id="LastMonth" size="3" maxlength="3"></td> </tr> <tr> <td><div align="right" class="style1">Business Type </div></td> <td><div align="left"> <select name="BusinessType" size="1" id="BusinessType"> <option value="VARS">VARS</option> <option value="Sole-Trader">Sole-Trader</option> <option value="Shop Front">Shop Front</option> </select> </div></td> <td><div align="right" class="style1">Last 3 Months </div></td> <td><input name="Last3Months" type="text" id="Last3Months" size="3" maxlength="3"></td> </tr> <tr> <td><div align="right" class="style1">Preferred Shipping Method</div></td> <td><div align="left"> <select name="PreferredShippingMethod" size="1" id="PreferredShippingMethod"> <option value="Synnex Preferred Shipping">Synnex Preferred Shipping</option> <option value="Customer Courier Pickup">Customer Courier Pickup</option> <option value="Customer Pickup">Customer Pickup</option> <option value="Air Normal">Air Normal</option> <option value="Air Express">Air Express</option> </select> </div></td> <td><div align="right" class="style1">YTD</div></td> <td><input name="YTD" type="text" id="YTD" size="3" maxlength="3"></td> </tr> </table></td> </tr> <tr> <td valign="top"><div align="left"></div> <table width="400" border="0" align="left" cellpadding="5" cellspacing="0"> <tr> <td><div align="right" class="style1">PostCode:</div></td> <td><div align="left"> <input name="Postcode" type="text" id="Postcode" size="4" maxlength="4"> </div></td> <td><div align="right" class="style1">Email</div></td> <td><div align="left"> <input name="Email" type="text" id="Email" size="35"> </div></td> </tr> <tr> <td><div align="right" class="style1">Telephone # </div></td> <td><div align="left"> <input name="Telephone" type="text" id="Telephone" size="13" maxlength="13"> </div></td> <td><div align="right" class="style1">FAX # </div></td> <td><div align="left"> <input name="FAX" type="text" id="FAX" size="13" maxlength="13"> </div></td> </tr> <tr> <td><div align="right" class="style1">TDR/AREA code:</div></td> <td><div align="left"> <input name="tdr" type="text" id="tdr"> </div></td> <td colspan="2"> </td> </tr> </table></td> </tr> <tr> <td rowspan="2" valign="top"><div align="justify"> </div> <textarea name="Notes" cols="60" rows="10" id="Notes">Please insert notes about the general account</textarea></td> <td><table width="400" border="0" cellspacing="0" cellpadding="5"> <tr> <td><div align="right" class="style1">Product Focus</div></td> <td><div align="left"> <select name="ProductFocus" size="1" id="ProductFocus"> <option value="Hardware">Hardware</option> <option value="Software">Software</option> <option value="Solution Selling">Solution Selling</option> <option value="Service">Service</option> <option value="Telecommunications">Telecommunications</option> <option value="Other">Other</option> </select> </div></td> </tr> <tr> <td><div align="right" class="style1">New Customer? </div></td> <td><div align="left"> <input name="NewCustomer" type="checkbox" id="NewCustomer"> </div></td> </tr> </table></td> </tr> <tr> <td><table width="400" border="0" align="right" cellpadding="2" cellspacing="5"> <tr> <td colspan="4"><div align="left" class="style1">Principle Purchasing History: </div></td> </tr> <tr> <td><div align="right">OEM (CPU/Motherboard/HDD/Memory):</div></td> <td><div align="center"> <input name="Oem" type="checkbox" id="Oem"> </div></td> <td><div align="right">System (PC/Notebook):</div></td> <td><div align="center"> <input name="System" type="checkbox" id="System"> </div></td> </tr> <tr> <td><div align="right">Peripherals (LCD/Printers/Networking/KB/MS):</div></td> <td><div align="center"> <input name="Peripherals" type="checkbox" id="Peripherals"> </div></td> <td><div align="right">Consumables:</div></td> <td><div align="center"> <input name="Consumables" type="checkbox" id="Consumables"> </div></td> </tr> <tr> <td><div align="right">Telecommunications/GPS:</div></td> <td><div align="center"> <input name="Telecommunications" type="checkbox" id="Telecommunications"> </div></td> <td><div align="right">Other:</div></td> <td><div align="center"> <input name="Other" type="checkbox" id="Other"> </div></td> </tr> </table></td> </tr> <tr> <td><div align="right"> <input name="Input" type="submit" id="Input" value="Input Customer Details"> </div></td> <td><div align="left"> </div></td> </tr> <tr> <td colspan="2"><table width="800" border="0" cellspacing="3" cellpadding="0"> <tr> <td><div align="left" class="style1">Date/Time:</div></td> <td><div align="left" class="style1">Notes:</div></td> </tr> <tr> <td><input name="Date" type="text" id="Date"></td> <td><textarea name="Callout" cols="100" rows="3" id="Callout"></textarea></td> </tr> <tr> <td><span class="style2"></span></td> <td> </td> </tr> </table></td> </tr> </table> </div> <input type="hidden" name="MM_insert" value="InputCustomer"> <input type="hidden" name="MM_insert" value="InputCustomer"> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/112390-help-required-with-sessions-2-sessions-on-one-page/ Share on other sites More sharing options...
.josh Posted June 29, 2008 Share Posted June 29, 2008 Quick and dirty example: form.php <?php session_start(); // echo out errors. Nothing will echo out if first time visit foreach($_SESSION['errors'] as $error) { echo "$error <br />"; } // end foreach error unset($_SESSION['errors']; // echo out form. Default values previous entered in stuff if applicable echo <<<FORMENT <form action = 'process.php' method = 'post'> First Name:<input type = 'text' name = 'fname' value = '{$_SESSION['fname']}'> <br /> Last Name:<input type = 'text' name = 'lname' value = '{$_SESSION['lname']}'> <br /> <input type = 'submit' value = 'submit'> </form> FORMENT; ?> process.php <?php session_start(); // check to see if fname was filled out. If not... if(!$_POST['fname'] || (trim($_POST['fname']) == '')) { // make an error msg session array $_SESSION['errors'][] = "Need to fill out first name."; // if filled out... } else { // create a session var for fname // also might want to sanitize... $_SESSION['fname'] = $_POST['fname']; } // end if..else fname // check to see if lname was filled out. If not... if(!$_POST['lname'] || (trim($_POST['lname']) == '')) { // make an error msg session array $_SESSION['errors'][] = "Need to fill out last name."; // if filled out... } else { // create a session var for lname // also might want to sanitize... $_SESSION['lname'] = $_POST['lname']; } // end if..else lname // if there are errors... if($_SESSION['errors']) { // send user back to form header("Location: form.php"); // if no errors generated... } else { // insert into db code here. } // end if..else errors ?> Link to comment https://forums.phpfreaks.com/topic/112390-help-required-with-sessions-2-sessions-on-one-page/#findComment-577014 Share on other sites More sharing options...
goldenbrown21 Posted June 29, 2008 Author Share Posted June 29, 2008 Thanks for the example! Link to comment https://forums.phpfreaks.com/topic/112390-help-required-with-sessions-2-sessions-on-one-page/#findComment-577215 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.