Session variable help
Posted on
16th Feb 2014 07:03 pm by
admin
I'm having a very troubling issue. Maybe I'm just looking over something but I have looked at the code for several hours now, making small adjustments here and there to try to fix this problem. Basically what I am doing is trying to POST the values of this form into my next php file which then records it to a database and mails it to me. I am validating the information submitted on the form in my php executing file. The problem occurs whenever a person does not completely fill out the form and causes it to send back the error messages. My code refills the textboxes and dropdown boxes with the previously information but when it comes to checkboxes it does not at the moment. I took this functionality out for the time being because I found out that when the form is resubmitted the checkboxes are no longer even POSTing the correct values anymore when checked. I have a little test at the bottom of my form to show me the values that my php exec file is sending back (located in the echo $c $obj part) All future submissions after the person submits the form the first time with errors will result in the checkboxes POSTing no value at all even if they are checked. I can't figure out where the value is getting lost...
Code: ###### student-registration.php ######
<html>
<head>
<title>Registration Form</title>
<link href="loginmodule.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="jquery-1.2.1.pack.js"></script>
<script type="text/javascript">
function carryOver(def,obj) {
var control = document.getElementById(obj);
control.value = def;
}
function disChange() {
if(document.getElementById('hidDiagnostic').style.display=='none') {
document.getElementById('hidDiagnostic').style.display = "block";
}else {
document.getElementById('hidDiagnostic').style.display = "none";
}
}
function lookup(inputString) {
if(inputString.length == 0) {
$('#schoolSystems').hide();
} else {
$.post("schoolsystemlookup-exec.php", {ss: ""+inputString+""}, function(data){
if(data.length >0) {
$('#schoolSystems').show();
$('#schoolSystemsList').html(data);
}
});
}
} // lookup
function fill(thisValue) {
$('#ss').val(thisValue);
setTimeout("$('#schoolSystems').hide();", 200);
}
</script>
</head>
<body>
<?php
session_start();
if( isset($_SESSION['ERRMSG_ARR']) && is_array($_SESSION['ERRMSG_ARR']) && count($_SESSION['ERRMSG_ARR']) >0 ) {
echo '<h1>Error! Form will not be processed till mistakes are fixed</h1>';
echo '<ul class="err">';
foreach($_SESSION['ERRMSG_ARR'] as $msg) {
echo '<li>',$msg,'</li>';
}
echo '</ul>';
unset($_SESSION['ERRMSG_ARR']);
}
?>
<div id="hStudent" style="width:100%; height:50px; background-color:#EAE9E4; color:#FF0000; font-size:40px;">
<b>Basic Student Information</b>
</div>
<form action="studentregistration-exec.php" method="post">
<table>
<tr>
<td>Student First Name:</td>
<td><input type="text" name="stuFName" id="stuFName"/></td>
</tr>
<tr>
<td>Student Last Name:</td>
<td><input type="text" name="stuLName" id="stuLName"/></td>
</tr>
<tr>
<td>Student Grade:</td>
<td><select name="stuGrade" id="stuGrade">
<option value="IP">Infant Program</option>
<option value="PS">Pre-School Program</option>
<option value="KG">K</option>
<option value="01">1</option>
<option value="02">2</option>
<option value="03">3</option>
<option value="04">4</option>
<option value="05">5</option>
<option value="06">6</option>
<option value="07">7</option>
<option value="08">8</option>
<option value="09">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="PG">College</option>
<option value="V">Vocational</option>
<option value="A">Adult Rehabilitation</option>
<option value="OR">Other</option>
</select></td>
</tr>
<tr>
<td>Date of Birth:</td>
<td><select name="bMonth" id="bMonth">
<option value="01">January</option>
<option value="02">February</option>
<option value="03">March</option>
<option value="04">April</option>
<option value="05">May</option>
<option value="06">June</option>
<option value="07">July</option>
<option value="08">August</option>
<option value="09">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<select name="bDate" id="bDate">
<?php
for($d = 1; $d <= 31; $d++) {
if($d < 10) { echo "<option value='0$d'>0$d</option>";
} else{ echo "<option value='$d'>$d</option>";}
}
?>
</select>
<select name="bYear" id="bYear">
<?php
for($y = date("Y"); $y >= (date("Y")-110); $y--) {
echo "<option value='$y'>$y</option>";
}
?>
</select></td>
</tr>
<tr>
<td>Address #1:</td>
<td><input type="text" name="stuAddOne" id="stuAddOne"/></td>
</tr>
<tr>
<td>Address #2 (optional):</td>
<td><input type="text" name="stuAddTwo" id="stuAddTwo"/></td>
</tr>
<tr>
<td>City/Zip:</td>
<td><input type="text" name="stuCity" id="stuCity"/>
<input type="number" size=3 maxlength=5 name="stuZip" id="stuZip"/></td>
</tr>
</table>
<div id="hSchool" style="width:100%; height:50px; background-color:#EAE9E4; color:#FF0000; font-size:40px;">
<b>School and Material Information</b>
</div>
<table>
<tr>
<td>School System:</td>
<td><input type="text" onkeyup="lookup(this.value);" name="ss" id="ss" />
<div class="suggestionsBox" id="schoolSystems" style="display: none;">
<img src="upArrow.png" style="position: relative; top: -12px; left: 50px" alt="upArrow" />
<div class="suggestionList" id="schoolSystemsList">
</div>
</div></td>
</tr>
<tr>
<td>Transfer Student: </td>
<td><input type="checkbox" value="-1" name="stuTransfer" id="stuTransfer"/></td>
</tr>
<tr>
<td>Primary Reading Material: </td>
<td><select name="readMaterial" id="readMaterial">
<option value="LP">Large Print</option>
<option value="BR">Braille</option>
<option value="AU">Audio</option>
<option value="ET">Electronic Text</option>
</select></td>
</tr>
<tr>
<td>Individual Education Plan or 504 Plan on file?</td>
<td><select name="iep" id="iep">
<option value="-1">Yes</option>
<option value="0">No</option>
</select></td>
</tr>
<tr>
<td>Date Enrolled in School:</td>
<td><select name="enrMonth" id="enrMonth">
<option value="01">January</option>
<option value="02">February</option>
<option value="03">March</option>
<option value="04">April</option>
<option value="05">May</option>
<option value="06">June</option>
<option value="07">July</option>
<option value="08">August</option>
<option value="09">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<select name="enrDate" id="enrDate">
<?php
for($d = 1; $d <= 31; $d++) {
if($d < 10) { echo "<option value='0$d'>0$d</option>";
} else{ echo "<option value='$d'>$d</option>";}
}
?>
</select>
<select name="enrYear" id="enrYear">
<?php
for($y = date("Y"); $y >= (date("Y")-25); $y--) {
echo "<option value='$y'>$y</option>";
}
?>
</select></td>
</tr>
</table>
<div id="hSchool" style="width:100%; height:50px; background-color:#EAE9E4; color:#FF0000; font-size:40px;">
<b>Eligibility</b>
</div>
<table>
<tr>
<td>Print Disabilities:</td>
</tr>
<tr>
<td /><td>Visual Disability:</td>
<td><input type="checkbox" value="-1" onclick="disChange();" name="disVisual" id="disVisual"/></td>
</tr>
<tr>
<td /><td>Reading Disability:</td>
<td><input type="checkbox" value="-1" name="disReading" id="disReading"/></td>
</tr>
<tr>
<td /><td>Physical Disability:</td>
<td><input type="checkbox" value="-1" name="disPhysical" id="disPhysical"/></td>
</tr>
<tbody id="hidDiagnostic" style="display:none;">
<tr>
<td>Right Eye:</td>
<td>20 / <input type="text" name="eyeRight" id="eyeRight"/></td>
</tr>
<tr>
<td>Left Eye:</td>
<td>20 / <input type="text" name="eyeLeft" id="eyeLeft"/></td>
</tr>
</tbody>
</table>
<div id="hAuthorize" style="width:100%; height:50px; background-color:#EAE9E4; color:#FF0000; font-size:40px;">
<b>Authorizing Information</b>
</div>
I certify that the above information is accurate and fully documented:
<table>
<tr>
<td>Name:</td>
<td><input type="text" name="authName" id="authName"/></td>
</tr>
<tr>
<td>Position/Title:</td>
<td><input type="text" name="authTitle" id="authTitle"/></td>
</tr>
<tr>
<td>Phone Number:</td>
<td>(<input type="text" size=1 maxlength=3 name="authArea" id="authArea"/>) <input type="text" size=1 maxlength=3 name="authPhoneOne" id="authPhoneOne"/> - <input type="text" size=2 maxlength=4 name="authPhoneTwo" id="authPhoneTwo"/></td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" name="authEmail" id="authEmail"/></td>
</tr>
<tr>
<td>Address:</td>
<td><input type="text" name="authAddress" id="authAddress"/></td>
</tr>
<tr>
<td>City/Zip:</td>
<td><input type="text" name="authCity" id="authCity"/> <input type="number" size=3 maxlength=5 name="authZip" id="authZip"/></td>
</tr>
</table>
<input type="submit" value="Submit"/>
</form>
<?php
if( isset($_SESSION['FORM_ARR']) && is_array($_SESSION['FORM_ARR']) && count($_SESSION['FORM_ARR']) >0 ) {
$field_arr = array();
$field_arr[0]="stuFName";
$field_arr[1]="stuLName";
$field_arr[2]="stuGrade";
$field_arr[3]="bMonth";
$field_arr[4]="bDate";
$field_arr[5]="bYear";
$field_arr[6]="stuAddOne";
$field_arr[7]="stuAddTwo";
$field_arr[8]="stuCity";
$field_arr[9]="stuZip";
$field_arr[10]="ss";
$field_arr[11]="stuTransfer";
$field_arr[12]="readMaterial";
$field_arr[13]="iep";
$field_arr[14]="enrMonth";
$field_arr[15]="enrDate";
$field_arr[16]="enrYear";
$field_arr[17]="disVisual";
$field_arr[18]="disReading";
$field_arr[19]="disPhysical";
$field_arr[20]="eyeRight";
$field_arr[21]="eyeLeft";
$field_arr[22]="authName";
$field_arr[23]="authTitle";
$field_arr[24]="authArea";
$field_arr[25]="authPhoneOne";
$field_arr[26]="authPhoneTwo";
$field_arr[27]="authEmail";
$field_arr[28]="authAddress";
$field_arr[29]="authCity";
$field_arr[30]="authZip";
$c=0;
foreach($_SESSION['FORM_ARR'] as $obj) {
echo "<SCRIPT type='text/javascript'>carryOver('" . $obj . "','" . $field_arr[$c] . "');</SCRIPT>";
echo $c . " - " . $obj . "
";
$c++;
}
unset($_SESSION['FORM_ARR']);
}
?>
</body>
</html>Code: ##### studentregistration-exec.php #####
<?php
function session_restart()
{
if (session_name()=='') {
// Session not started yet
session_start();
}
else {
// Session was started, so destroy
session_destroy();
// But we do want a session started for the next request
session_start();
session_regenerate_id();
// PHP < 4.3.3, since it does not put
setcookie(session_name(), session_id());
}
}
//Start session
//session_start();
//Array to store validation errors
$errmsg_arr = array();
//Array to store previous form entries
$form_arr = array();
//Validation error flag
$errflag = false;
require_once('config.php');
$link = mysql_connect(DB_HOST, DBA_USER, DB_PASSWORD);
if(!$link) {
die('Failed to connect to server: ' . mysql_error());
}
$db = mysql_select_db(DBA_DATABASE);
if(!$db) {
die("Unable to select database");
}
//Function to sanitize values received from the form. Prevents SQL injection
function clean($str) {
$str = @trim($str);
if(get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return mysql_real_escape_string($str);
}
$form_arr[0] = $stuFName = clean($_POST['stuFName']);
$form_arr[1] = $stuLName = clean($_POST['stuLName']);
$form_arr[2] = $stuGrade = clean($_POST['stuGrade']);
$form_arr[3] = $bMonth = clean($_POST['bMonth']);
$form_arr[4] = $bDate = clean($_POST['bDate']);
$form_arr[5] = $bYear = clean(
No comments posted yet
Your Answer:
Login to answer
150
39
Other forums
first few characters only
hi, does anyone know how to use PHP to take the first few words of a text and limit them? i have see
Need understanding of this bit of code
Code: <?php
// WHERE clause filters
$arrSQLFilters = array();
//
Two warning messages
Quote<b>Warning</b>: mysql_real_escape_string() expects parameter 1 to
Production of mango in processing industry
Hi,
We have one scenario ,company is in process industry,they are manufacturing MANGO pul
cyrillic string conversion question
Hello,
First time here...
I would like to know if there is a way to convert a
whats wrong with my code please help!!!
this is the error
Warning: mysql_close(): supplied argument is not a valid MySQL-Link res
classic dynpro : hide area and auto adjust hights
Hi,
I want to develop a similar user interface as is used in standard transaction MIGO.
POST into Array problem
Hi Chaps,
I have a repeat region, displaying rows of data: jobid, fromtable, translatorcharge
passing an array of objects after submit
How do I do this? This is what I have tried and it is not working.
<form method="
Dynamically allocating the number of rows in a table based on a variable value
Hi,
I have situation here which i cannot resolve, I have a variable temp which stores the num