Jump to content

Retrieving SESSION vars


matt.sisto

Recommended Posts

Hi,

I have written a form for a user to book some time with a consultant, but the user can check the availability of the consultant first. When the user returns to the form after running the check availability script the all the form input is reset, which is no good. I am trying to use SESSION to store the form input but my script just won't work. I have never used SESSION before so I don't have a clue how to use it, so any help would be greatly appreciated.

bookingform.php:

<?php 

  session_start();
  
if (!isset($_SESSION['username']))
    {
header("Location: login.php");
exit();
    }
else if (!isset($_SESSION['values'])){
  $_SESSION['values'] ['year'] = ''; 
  $_SESSION['values'] ['month']=''; 
  $_SESSION['values'] ['day']= ''; 
  $_SESSION['values'] ['unit'] = ''; 
  $_SESSION['values'] ['quantity'] = ''; 
  $_SESSION['values'] ['start_time_hr'] = ''; 
  $_SESSION['values'] ['start_time_min'] = ''; 
  $_SESSION['values'] ['extra_info'] = ''; 
  $_SESSION['values'] ['con_id1'] = ''; 
  $_SESSION['values'] ['con_id2'] = ''; 
  $_SESSION['values'] ['con_id3'] = ''; 
}
else(isset($_SESSION['values'])){
  $_SESSION['values'] ['year'] =$_GET['year']; 
  $_SESSION['values'] ['month']=$_GET['month']; 
  $_SESSION['values'] ['day']=$_GET['day']; 
  $_SESSION['values'] ['unit'] = $_GET['unit']; 
  $_SESSION['values'] ['quantity'] = $_GET['quantity']; 
  $_SESSION['values'] ['start_time_hr'] =$_GET['start_time_hr']; 
  $_SESSION['values'] ['start_time_min'] = $_GET['start_time_min']; 
  $_SESSION['values'] ['extra_info'] = $_GET['extra_info']; 
  $_SESSION['values'] ['con_id1'] = $_GET['con_id1']; 
  $_SESSION['values'] ['con_id2'] = $_GET['con_id2']; 
  $_SESSION['values'] ['con_id3'] = $_GET['con_id3']; 
}

  if(isset($_GET['available1']) && $_GET['available1']=='true') {
    echo '<div id="available1true">Available: √</div>';
   }
  if(isset($_GET['available1']) && $_GET['available1']=='false') {
    echo '<div id="available1false">Not Available: X</div>';
   }

  if(isset($_GET['available2']) && $_GET['available2']=='true') {
    echo '<div id="available2true">Available: √</div>';
   }
  if(isset($_GET['available2']) && $_GET['available2']=='false') {
    echo '<div id="available2false">Not Available: X</div>';
   }

if(isset($_GET['available3']) && $_GET['available3']=='true') {
    echo '<div id="available3true">Available: √</div>';
   }
  if(isset($_GET['available3']) && $_GET['available3']=='false') {
    echo '<div id="available3false">Not Available: X</div>';
   }

require "dbconn2.php";

  $sql="SELECT service_id, service FROM service";
  $result=mysql_query($sql);
  $service_option="";
  
while ($row=mysql_fetch_array($result)) {

    $id=$row["service_id"];
    $service=$row["service"];
    $service_option.="<OPTION VALUE=\"$id\">".$service;
}
  $sql="SELECT con_id, first_name, last_name FROM consultant";
  $result=mysql_query($sql);
  $rconsultant_option="";

while ($row=mysql_fetch_array($result)) {

    $con_id=$row["con_id"];
    $first_name=$row["first_name"];
$last_name=$row["last_name"];
    $consultant_option1.="<OPTION VALUE=\"$con_id\">".$first_name." ".$last_name;
$consultant_option2.="<OPTION VALUE=\"$con_id\">".$first_name." ".$last_name;
    $consultant_option3.="<OPTION VALUE=\"$con_id\">".$first_name." ".$last_name;
}	
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>SRC: Booking Form</title>
<link href="master.css" rel="stylesheet" type="text/css">
<link rel="shortcut icon" type="image/ico" href="favicon.ico">
<script type="text/javascript">
<!--
function OnSubmitForm()
{
  if(document.pressed == 'Check')
  {
   document.bookingForm.action ="checkavailability1.php";
  }
  else if(document.pressed == 'Book')
  {
    document.bookingForm.action ="book.php";
  }
  return true;
}
//-->
</script>
</head>
<body>
<div id="centerPanel">
<div id="header">Booking Form</div><p>
<div id="content">
<form name="bookingForm" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" onSubmit="return OnSubmitForm();">
<label id="eventStart">Event Date:</label><br />
<select id="year3" name="year" value="<?php echo $_SESSION['values'] ['year']?>">
<?php
       $yeartoday = date(Y);
       $yearplus1 = date(Y)+1;
         for($y=$yeartoday;$y<=$yearplus1;$y++){  
           $selected = "";
           $longDate = date("Y", mktime(0,0,0,1,1,$y));
           if ($Year==$y){ 
            $selected = "selected \n";
           }
           echo "<option value=\"$y\" $selected>$longDate</option> \n";
         }
?>
</select>
<select id="month3" name="month" value="<?php echo $_SESSION['values'] ['month']?>"/>
<?php
$months = Array("Jan", "Feb", "Mar", "Apr", "May",  "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
for ($x=1; $x <= count($months); $x++) {
   echo"<option value=\"$x\"";
   if ($x == $month) {
      echo " selected";
   }
   echo ">".$months[$x-1]."</option>";
}
?>
</select>
<select id="day3" name="day" value="<?php echo $_SESSION['values'] ['day']?>">
<?php
for ($x= 1; $x<=31; $x++) {
   echo "<option";
   if ($x == $day) {
      echo " selected";
   }
   echo ">$x</option>";
}
?>
</select> 
<p>
  <label id="service">Service:</label><br />
  <select id="serviceSelect" name="service">
   <option value="<?php echo $_SESSION['values'] ['service']?>">Choose <?=$service_option?>
  </option>
  </select>
</p>  
<p>
  <label id="unit">Unit:</label><br />
  <input id="radioHour" type = 'Radio' name ='unit' value= 'hour'><label id="Hour">Hour</label>
  <input id="radioDay" type = 'Radio' name ='unit' value= 'day'><label id="Day">Day</label>
</p>  
<label id="quantity">Quantity:</label><br/>
<select id="quantSelect" name="quantity" value="<?php echo $_SESSION['values'] ['quantity']?>">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
</select>
<br />
<label id="eventStartTime">Start Time:</label><br/>
<select id="hour" name="start_time_hr" value="<?php echo $_SESSION['values'] ['start_time_hr']?>">
<option value="09">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
</select>
<select id="minute" name="start_time_min" value="<?php echo $_SESSION['values'] ['start_time_min']?>">
<option value="00">00</option>
<option value="15">15</option>
<option value="30">30</option>
<option value="45">45</option>
</select></p>
<br />
<label id="extraInfo">Extra Information:</label><br />
<textarea id="extraInfoInput" name="content" value="<?php echo $_SESSION['values'] ['extra_info']?>" onkeypress="return imposeMaxLength(this, 250);"></textarea>
<p>
<label id="con4">Consultant [1]:</label><br />
<select id="conSelect4" name="con_id1"><option value="<?php echo $_SESSION['values'] ['con_id1']?>">Choose <?=$consultant_option1?>
</option></select> 
<label id="con2">Consultant [2]:</label><br />
<select id="conSelect2" name="con_id2"><option value="<?php echo $_SESSION['values'] ['con_id2']?>">Choose <?=$consultant_option2?></option></select> 
<label id="con3">Consultant [3]:</label><br />
<select id="conSelect3" name="con_id3"><option value="<?php echo $_SESSION['values'] ['con_id3']?>">Choose <?=$consultant_option3?></option></select> 
<input  id= "check1" type ="submit" name="Check" onClick="document.pressed=this.value" value="Check"></p>
<p><input id="book" type ="submit" name="Book" onClick="document.pressed=this.value" value="Book"/></form>
</div>

</body>
</html>

 

checkavailability.php:

<?php

  session_start();

  if (!isset($_SESSION['username']))
    {
header("Location: login.php");
exit();
  }

  require "dbconn2.php";
  
  $month = mysql_real_escape_string($_POST["month"]);
  $day =  mysql_real_escape_string($_POST["day"]);
  $year=  mysql_real_escape_string($_POST["year"]);
  $con_id1=  mysql_real_escape_string($_POST["con_id1"]);
  $con_id2=  mysql_real_escape_string($_POST["con_id2"]); 
  $con_id3=  mysql_real_escape_string($_POST["con_id3"]); 
  
  $event_start = $year."-".$month."-".$day." ".$_POST["event_start"];

  if ($con_id1 != null){
  $sql = "SELECT * FROM calendar_events WHERE event_start='".$event_start."' AND (con_1='".$con_id1."' OR con_2='".$con_id1."' OR con_3='".$con_id1."')";

   $result = mysql_query ($sql, $connection) or die ("Could not perform query $sql <br />".mysql_error());
   $row = mysql_fetch_array($result);

if ($row != null){
      $available1 = "false";
  }
  else {
  $available1 = "true";
  }
  }
  if ($con_id2 != null){
  $sql = "SELECT * FROM calendar_events WHERE event_start='".$event_start."' AND (con_1='".$con_id2."' OR con_2='".$con_id2."' OR con_3='".$con_id2."')";

   $result = mysql_query ($sql, $connection) or die ("Could not perform query $sql <br />".mysql_error());
   $row = mysql_fetch_array($result);

if ($row != null){
      $available2 = "false";
  }
  else {
  $available2 = "true";
  }
  }
  if ($con_id3 != null){
  $sql = "SELECT * FROM calendar_events WHERE event_start='".$event_start."' AND (con_1='".$con_id3."' OR con_2='".$con_id3."' OR con_3='".$con_id3."')";

   $result = mysql_query ($sql, $connection) or die ("Could not perform query $sql <br />".mysql_error());
   $row = mysql_fetch_array($result);

if ($row != null){
      $available3 = "false";
  }
  else {
  $available3 = "true";
  }
  }

$url = "Location: bookingform.php?available1=$available1&available2=$available2&available3=$available3";
      header($url);
?>
<html>
<head>
<title>Check Availability</title>
</head>
<body>
</body>
</html>

 

Thanks and regs.

Link to comment
Share on other sites

<?php 

  session_start();

session_register ("year");	
session_register ("month");
session_register ("day");	
session_register ("service");
session_register ("unit");	
session_register ("start_time_hr");
session_register ("start_time_min");	
session_register ("extra_info");
session_register ("con_id1");
session_register ("con_id2");	
session_register ("con_id3");

$HTTP_SESSION_VARS ["year"] = $year;	
$HTTP_SESSION_VARS ["month"] = $month;
$HTTP_SESSION_VARS ["day"] = $day;	
$HTTP_SESSION_VARS ["service"] = $service;
$HTTP_SESSION_VARS ["unit"] = $unit;	
$HTTP_SESSION_VARS ["start_time_hr"] = $start_time_hr;
$HTTP_SESSION_VARS ["start_time_min"] = $start_time_min;	
$HTTP_SESSION_VARS ["extra_info"] = $extra_info;
$HTTP_SESSION_VARS ["con_id1"] = $con_id1;
$HTTP_SESSION_VARS ["con_id2"] = $con_id2;
$HTTP_SESSION_VARS ["con_id3"] = $con_id3;	

if (!isset($_SESSION['username']))
    {
   header("Location: login.php");
   exit();
    }
  if(isset($_GET['available1']) && $_GET['available1']=='true') {
    echo '<div id="available1true">Available: &#8730;</div>';
   }
  if(isset($_GET['available1']) && $_GET['available1']=='false') {
    echo '<div id="available1false">Not Available: X</div>';
   }

  if(isset($_GET['available2']) && $_GET['available2']=='true') {
    echo '<div id="available2true">Available: &#8730;</div>';
   }
  if(isset($_GET['available2']) && $_GET['available2']=='false') {
    echo '<div id="available2false">Not Available: X</div>';
   }

if(isset($_GET['available3']) && $_GET['available3']=='true') {
    echo '<div id="available3true">Available: &#8730;</div>';
   }
  if(isset($_GET['available3']) && $_GET['available3']=='false') {
    echo '<div id="available3false">Not Available: X</div>';
   }

require "dbconn2.php";

  $sql="SELECT service_id, service FROM service";
  $result=mysql_query($sql);
  $service_option="";
  
while ($row=mysql_fetch_array($result)) {

    $id=$row["service_id"];
    $service=$row["service"];
    $service_option.="<OPTION VALUE=\"$id\">".$service;
   }
  $sql="SELECT con_id, first_name, last_name FROM consultant";
  $result=mysql_query($sql);
  $rconsultant_option="";

while ($row=mysql_fetch_array($result)) {

    $con_id=$row["con_id"];
    $first_name=$row["first_name"];
   $last_name=$row["last_name"];
    $consultant_option1.="<OPTION VALUE=\"$con_id\">".$first_name." ".$last_name;
   $consultant_option2.="<OPTION VALUE=\"$con_id\">".$first_name." ".$last_name;
    $consultant_option3.="<OPTION VALUE=\"$con_id\">".$first_name." ".$last_name;
}   
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>SRC: Booking Form</title>
<link href="master.css" rel="stylesheet" type="text/css">
<link rel="shortcut icon" type="image/ico" href="favicon.ico">
<script type="text/javascript">
<!--
function OnSubmitForm()
{
  if(document.pressed == 'Check')
  {
   document.bookingForm.action ="checkavailability1.php";
  }
  else if(document.pressed == 'Book')
  {
    document.bookingForm.action ="book.php";
  }
  return true;
}
//-->
</script>
</head>
<body>
<div id="centerPanel">
<div id="header">Booking Form</div><p>
<div id="content">
<form name="bookingForm" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" onSubmit="return OnSubmitForm();">
<label id="eventStart">Event Date:</label><br />
<select id="year3" name="year" value="<?php echo $_SESSION['values'] ['year']?>">
<?php
       $yeartoday = date(Y);
       $yearplus1 = date(Y)+1;
         for($y=$yeartoday;$y<=$yearplus1;$y++){  
           $selected = "";
           $longDate = date("Y", mktime(0,0,0,1,1,$y));
           if ($Year==$y){ 
            $selected = "selected \n";
           }
           echo "<option value=\"$y\" $selected>$longDate</option> \n";
         }
?>
</select>
<select id="month3" name="month" value="<?php echo $_SESSION['values'] ['month']?>"/>
<?php
$months = Array("Jan", "Feb", "Mar", "Apr", "May",  "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
for ($x=1; $x <= count($months); $x++) {
   echo"<option value=\"$x\"";
   if ($x == $month) {
      echo " selected";
   }
   echo ">".$months[$x-1]."</option>";
}
?>
</select>
<select id="day3" name="day" value="<?php echo $_SESSION['values'] ['day']?>">
<?php
for ($x= 1; $x<=31; $x++) {
   echo "<option";
   if ($x == $day) {
      echo " selected";
   }
   echo ">$x</option>";
}
?>
</select>
<p>
  <label id="service">Service:</label><br />
  <select id="serviceSelect" name="service">
   <option value="<?php echo $_SESSION['values'] ['service']?>">Choose <?=$service_option?>
  </option>
  </select>
</p> 
<p>
  <label id="unit">Unit:</label><br />
  <input id="radioHour" type = 'Radio' name ='unit' value= 'hour'><label id="Hour">Hour</label>
  <input id="radioDay" type = 'Radio' name ='unit' value= 'day'><label id="Day">Day</label>
</p> 
<label id="quantity">Quantity:</label><br/>
<select id="quantSelect" name="quantity" value="<?php echo $_SESSION['values'] ['quantity']?>">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
</select>
<br />
<label id="eventStartTime">Start Time:</label><br/>
<select id="hour" name="start_time_hr" value="<?php echo $_SESSION['values'] ['start_time_hr']?>">
<option value="09">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
</select>
<select id="minute" name="start_time_min" value="<?php echo $_SESSION['values'] ['start_time_min']?>">
<option value="00">00</option>
<option value="15">15</option>
<option value="30">30</option>
<option value="45">45</option>
</select></p>
<br />
<label id="extraInfo">Extra Information:</label><br />
<textarea id="extraInfoInput" name="content" value="<?php echo $_SESSION['values'] ['extra_info']?>" onkeypress="return imposeMaxLength(this, 250);"></textarea>
<p>
<label id="con4">Consultant [1]:</label><br />
<select id="conSelect4" name="con_id1"><option value="<?php echo $_SESSION['values'] ['con_id1']?>">Choose <?=$consultant_option1?>
</option></select>
<label id="con2">Consultant [2]:</label><br />
<select id="conSelect2" name="con_id2"><option value="<?php echo $_SESSION['values'] ['con_id2']?>">Choose <?=$consultant_option2?></option></select>
<label id="con3">Consultant [3]:</label><br />
<select id="conSelect3" name="con_id3"><option value="<?php echo $_SESSION['values'] ['con_id3']?>">Choose <?=$consultant_option3?></option></select>
<input  id= "check1" type ="submit" name="Check" onClick="document.pressed=this.value" value="Check"></p>
<p><input id="book" type ="submit" name="Book" onClick="document.pressed=this.value" value="Book"/></form>
</div>
</body>
</html>

I have tried to change my booking form to this, but still I can not retrieve the SESSION var values? the form just resets?

Link to comment
Share on other sites

<?php 

  session_start();
  
if (!isset($_SESSION['username']))
    {
   header("Location: login.php");
   exit();
    }
if (!isset($_SESSION['values'])){
  $_SESSION['values']['year'] = ''; 
  $_SESSION['values']['month']=''; 
  $_SESSION['values']['day']= ''; 
  $_SESSION['values']['unit'] = ''; 
  $_SESSION['values']['quantity'] = ''; 
  $_SESSION['values']['start_time_hr'] = ''; 
  $_SESSION['values']['start_time_min'] = ''; 
  $_SESSION['values']['extra_info'] = ''; 
  $_SESSION['values']['con_id1'] = ''; 
  $_SESSION['values']['con_id2'] = ''; 
  $_SESSION['values']['con_id3'] = ''; 
}
else{
  $_SESSION['values']['year']=$_POST['year']; 
  $_SESSION['values']['month']=$_POST['month']; 
  $_SESSION['values']['day']=$_POST['day']; 
  $_SESSION['values']['unit'] = $_POST['unit']; 
  $_SESSION['values']['quantity'] = $_POST['quantity']; 
  $_SESSION['values']['start_time_hr'] =$_POST['start_time_hr']; 
  $_SESSION['values']['start_time_min'] = $_POST['start_time_min']; 
  $_SESSION['values']['extra_info'] = $_POST['extra_info']; 
  $_SESSION['values']['con_id1'] = $_POST['con_id1']; 
  $_SESSION['values']['con_id2'] = $_POST['con_id2']; 
  $_SESSION['values']['con_id3'] = $_POST['con_id3']; 
}

  if(isset($_GET['available1']) && $_GET['available1']=='true') {
    echo '<div id="available1true">Available: √</div>';
   }
  if(isset($_GET['available1']) && $_GET['available1']=='false') {
    echo '<div id="available1false">Not Available: X</div>';
   }

  if(isset($_GET['available2']) && $_GET['available2']=='true') {
    echo '<div id="available2true">Available: √</div>';
   }
  if(isset($_GET['available2']) && $_GET['available2']=='false') {
    echo '<div id="available2false">Not Available: X</div>';
   }

if(isset($_GET['available3']) && $_GET['available3']=='true') {
    echo '<div id="available3true">Available: √</div>';
   }
  if(isset($_GET['available3']) && $_GET['available3']=='false') {
    echo '<div id="available3false">Not Available: X</div>';
   }

require "dbconn2.php";

  $sql="SELECT service_id, service FROM service";
  $result=mysql_query($sql);
  $service_option="";
  
while ($row=mysql_fetch_array($result)) {

    $id=$row["service_id"];
    $service=$row["service"];
    $service_option.="<OPTION VALUE=\"$id\">".$service;
}
  $sql="SELECT con_id, first_name, last_name FROM consultant";
  $result=mysql_query($sql);
  $rconsultant_option="";

while ($row=mysql_fetch_array($result)) {
    $con_id=$row["con_id"];
    $first_name=$row["first_name"];
$last_name=$row["last_name"];
    $consultant_option1.="<OPTION VALUE=\"$con_id\">".$first_name." ".$last_name;
$consultant_option2.="<OPTION VALUE=\"$con_id\">".$first_name." ".$last_name;
    $consultant_option3.="<OPTION VALUE=\"$con_id\">".$first_name." ".$last_name;
}	
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>SRC: Booking Form</title>
<link href="master.css" rel="stylesheet" type="text/css">
<link rel="shortcut icon" type="image/ico" href="favicon.ico">
<script type="text/javascript">
<!--
function OnSubmitForm()
{
  if(document.pressed == 'Check')
  {
   document.bookingForm.action ="checkavailability1.php";
  }
  else if(document.pressed == 'Book')
  {
    document.bookingForm.action ="book.php";
  }
  return true;
}
//-->
</script>
</head>
<body>
<div id="centerPanel"><div id="header">Booking Form</div><p>
<div id="content">
<form name="bookingForm" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" onSubmit="return OnSubmitForm();">

<label id="eventStart">Event Date:</label><br />
<select id="year3" name="year" value="<?php echo $_SESSION['values'] ['year']?>">
<?php
       $yeartoday = date(Y);
       $yearplus1 = date(Y)+1;
         for($y=$yeartoday;$y<=$yearplus1;$y++){  
           $selected = "";
           $longDate = date("Y", mktime(0,0,0,1,1,$y));
           if ($Year==$y){ 
            $selected = "selected \n";
           }
           echo "<option value=\"$y\" $selected>$longDate</option> \n";
         }
?>
</select>

<select id="month3" name="month" value="<?php echo $_SESSION['values'] ['month']?>">
<?php
$months = Array("Jan", "Feb", "Mar", "Apr", "May",  "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
for ($x=1; $x <= count($months); $x++) {
   echo"<option value=\"$x\"";
   if ($x == $month) {
      echo " selected";
   }
   echo ">".$months[$x-1]."</option>";
}
?>
</select>

<select id="day3" name="day" value="<?php echo $_SESSION['values'] ['day']?>">
<?php
for ($x= 1; $x<=31; $x++) {
   echo "<option";
   if ($x == $day) {
      echo " selected";
   }
   echo ">$x</option>";
}
?>
</select>

  <p>
  <label id="service">Service:</label><br />
  <select id="serviceSelect" name="service">
   <option value="<?php echo $_SESSION['values'] ['service']?>">Choose <?=$service_option?>
  </option>
  </select>
  </p>
  
  <p>
  <label id="unit">Unit:</label><br />
  <input id="radioHour" type = 'Radio' name ='unit' value= 'hour'><label id="Hour">Hour</label>
  <input id="radioDay" type = 'Radio' name ='unit' value= 'day'><label id="Day">Day</label>
  </p>
  
<label id="quantity">Quantity:</label><br/>
<select id="quantSelect" name="quantity" value="<?php echo $_SESSION['values'] ['quantity']?>">

<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
</select>
<br />
<label id="eventStartTime">Start Time:</label><br/>
<select id="hour" name="start_time_hr" value="<?php echo $_SESSION['values'] ['start_time_hr']?>">

<option value="09">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
</select>

<select id="minute" name="start_time_min" value="<?php echo $_SESSION['values'] ['start_time_min']?>">

<option value="00">00</option>
<option value="15">15</option>
<option value="30">30</option>
<option value="45">45</option>

</select></p>
<br />

<label id="extraInfo">Extra Information:</label><br />
<textarea id="extraInfoInput" name="content" value="<?php echo $_SESSION['values'] ['extra_info']?>" onkeypress="return imposeMaxLength(this, 250);"></textarea>

<p>
<label id="con4">Consultant [1]:</label><br />
<select id="conSelect4" name="con_id1"><option value="<?php echo $_SESSION['values'] ['con_id1']?>">Choose <?=$consultant_option1?>
</option></select> 

<label id="con2">Consultant [2]:</label><br />
<select id="conSelect2" name="con_id2"><option value="<?php echo $_SESSION['values'] ['con_id2']?>">Choose <?=$consultant_option2?></option></select> 

<label id="con3">Consultant [3]:</label><br />
<select id="conSelect3" name="con_id3"><option value="<?php echo $_SESSION['values'] ['con_id3']?>">Choose <?=$consultant_option3?></option></select> 

<input  id= "check1" type ="submit" name="Check" onClick="document.pressed=this.value" value="Check"></p>
<p><input id="book" type ="submit" name="Book" onClick="document.pressed=this.value" value="Book"/></form>
</div>
</body>
</html>

 

So now its semi working, the day and month do not reset but everything else does? I just can't work it out. ???

Link to comment
Share on other sites

<?php 

  session_start();
  
if (!isset($_SESSION['username']))
    {
   header("Location: login.php");
   exit();
    }

if (!isset($_SESSION['values'])){
  $_SESSION['values']['year']=''; 
  $_SESSION['values']['month']=''; 
  $_SESSION['values']['day']=''; 
  $_SESSION['values']['service']=''; 
  $_SESSION['values']['unit']=''; 
  $_SESSION['values']['quantity']=''; 
  $_SESSION['values']['start_time_hr']=''; 
  $_SESSION['values']['start_time_min']=''; 
  $_SESSION['values']['extra_info']=''; 
  $_SESSION['values']['con_id1']=''; 
  $_SESSION['values']['con_id2']=''; 
  $_SESSION['values']['con_id3']=''; 
}
else{
  $_SESSION['values']['year']=$_POST['year']; 
  $_SESSION['values']['month']=$_POST['month']; 
  $_SESSION['values']['day']=$_POST['day']; 
  $_SESSION['values']['service']=$_POST['service']; 
  $_SESSION['values']['unit']=$_POST['unit']; 
  $_SESSION['values']['quantity']=$_POST['quantity']; 
  $_SESSION['values']['start_time_hr']=$_POST['start_time_hr']; 
  $_SESSION['values']['start_time_min']=$_POST['start_time_min']; 
  $_SESSION['values']['extra_info']=$_POST['extra_info']; 
  $_SESSION['values']['con_id1']=$_POST['con_id1']; 
  $_SESSION['values']['con_id2']=$_POST['con_id2']; 
  $_SESSION['values']['con_id3']=$_POST['con_id3']; 
}

  if(isset($_GET['available1']) && $_GET['available1']=='true') {
    echo '<div id="available1true">Available: √</div>';
   }
  if(isset($_GET['available1']) && $_GET['available1']=='false') {
    echo '<div id="available1false">Not Available: X</div>';
   }
  if(isset($_GET['available2']) && $_GET['available2']=='true') {
    echo '<div id="available2true">Available: √</div>';
   }
  if(isset($_GET['available2']) && $_GET['available2']=='false') {
    echo '<div id="available2false">Not Available: X</div>';
   }
  if(isset($_GET['available3']) && $_GET['available3']=='true') {
    echo '<div id="available3true">Available: √</div>';
   }
  if(isset($_GET['available3']) && $_GET['available3']=='false') {
    echo '<div id="available3false">Not Available: X</div>';
   }

require "dbconn2.php";

  $sql="SELECT service_id, service FROM service";
  $result=mysql_query($sql);
  $service_option="";
  
while ($row=mysql_fetch_array($result)) {
    $id=$row["service_id"];
    $service=$row["service"];
    $service_option.="<OPTION VALUE=\"$id\">".$service;
  }

  $sql="SELECT con_id, first_name, last_name FROM consultant";
  $result=mysql_query($sql);
  $rconsultant_option="";

while ($row=mysql_fetch_array($result)) {
    $con_id1=$row["con_id"];
    $con_id2=$row["con_id"];
    $con_id3=$row["con_id"];
    $first_name=$row["first_name"];
    $last_name=$row["last_name"];
    $consultant_option1.="<OPTION VALUE=\"$con_id1\">".$first_name." ".$last_name;
    $consultant_option2.="<OPTION VALUE=\"$con_id2\">".$first_name." ".$last_name;
    $consultant_option3.="<OPTION VALUE=\"$con_id3\">".$first_name." ".$last_name;
  }	
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>SRC: Booking Form</title>
<link href="master.css" rel="stylesheet" type="text/css">
<link rel="shortcut icon" type="image/ico" href="favicon.ico">
<script type="text/javascript">
<!--
function OnSubmitForm()
{
  if(document.pressed == 'Check')
  {
   document.bookingForm.action ="checkavailability1.php";
  }
  else if(document.pressed == 'Book')
  {
    document.bookingForm.action ="book.php";
  }
  return true;
}
//-->
</script>
</head>
<body>
<div id="topbanner"><h1>Salmons Reach Consultancy</h1><h2>Striving to achieve excellence</h2></div><div id="salmon"><img src="Salmon.png" /></div>
<div id="loginRegister">
<a id="location" href="">Login </a>|  <a href="register.php">Register</a>
</div>
<div id="border">
</div>
<div id="quickLinks">
<ul><p>
      <li id="Title">QUICK LINKS</li><p>
      <li id="Title1"><a href="index.php"><b>HOME</b></a></li>
      <li><a href="work.php">Work</a></li>
      <li><a href="play.php">Play</a></li>
      <li><a href="future.php">Future</a></li>
      <li><a href="present.php">Present</a></li><p>
      <li id="Title1"><a href="history.php"><b>HISTORY</b></a></li>
      <li><a href="past.php">Past</a></li>
      <li><a href="staff.php">Staff</a></li>
      <li><a href="direction.php">Direction</a></li>
      <li><a href="destination.php">Destination</a></li><p>
      <li id="Title1"><a href="portfolio.php"><b>PORTFOLIO</b></a></li>
      <li><a href="thurrock.php">Thurrock</a></li>
      <li><a href="aru.php">Anglia Ruskin University</a></li>
      <li><a href="stgeorges.php">St Georges</a></li>
      <li><a href="malaysia.php">Malaysia</a></li><p>
      <li id="Title1"><a href="services.php"><b>SERVICES</b></a></li>
      <li><a href="consultancy.php">Consultancy</a></li>
      <li><a href="pd.php">Personal Development</a></li>
      <li><a href="project.php">Project Guidance and Initiation</a></li>
      <li><a href="od.php">Organisational Development</a></li><p>
      <li id="Title1"><a href="contact.php"><b>CONTACT</b></a></li>
      <li><a href="technical.php">Technical Support</a></li>
      <li><a href="regInterest.php">Register Interest For Services</a></li>
      <li><a href="message.php">Message Consultant</a></li><p>
</ul>
</div>
<div id="menu">
<ul>
  <li><input id="button1" type="button" value="Home" onclick="parent.location = 'index.php'" />
     <ul>
      <li><a href="work.php">[Work]</a></li>
      <li><a href="play.php">[Play]</a></li>
      <li><a href="future.php">[Future]</a></li>
      <li><a href="present.php">[Present]</a></li>
    </ul>
  </li>
  <li><input id="button2" type="button" onclick="parent.location = 'history.php'" value="History" />
    <ul>
      <li><a href="past.php">[Past]</a></li>
      <li><a href="staff.php">[staff]</a></li>
      <li><a href="direction.php">[Direction]</a></li>
      <li><a href="destination.php">[Destination]</a></li>
    </ul>
  </li>
    <li><input id="button3" type="button" onclick="parent.location = 'portfolio.php'" value="Portfolio" />
    <ul>
      <li><a href="thurrock.php">[Thurrock]</a></li>
      <li><a href="aru.php">[Anglia Ruskin University]</a></li>
      <li><a href="stgeorges.php">[st Georges]</a></li>
      <li><a href="malaysia.php">[Malaysia]</a></li>
    </ul>
  </li>
    <li><input id="button4" type="button" onclick="parent.location = 'services.php'" value="Services" />
    <ul>
      <li><a href="consultancy.php">[Consultancy]</a></li>
      <li><a href="pd.php">[Personal Development]</a></li>
      <li><a href="project.php">[Project Guidance and Initiation]</a></li>
      <li><a href="od.php">[Organisational Development]</a></li>
    </ul>
  </li>	
    <li><input id="button5" type="button" onclick="parent.location = 'contact.php'" value="contact" />
    <ul>
      <li><a href="technical.php">[Technical Support]</a></li>
      <li><a href="regInterest.php">[Register Interest For Services]</a></li>
      <li><a href="message.php">[Message Consultant]</a></li>
    </ul>
  </li>
  <li><input id="button5" type="button" value="Back" onClick="history.go(-1)">
  </li>
</ul>
</div>
</div><div id="centerPanel1">
</div>
<div id="rightPanel1">
</div>
<div id="centerPanel"><div id="header">Booking Form</div><p>
<div id="content">
<form name="bookingForm" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" onSubmit="return OnSubmitForm();">
<label id="eventStart">Event Date:</label><br />
<select id="year3" name="year" value="<?php echo $_SESSION['values']['year']?>">
<?php
       $yeartoday = date(Y);
       $yearplus1 = date(Y)+1;
         for($y=$yeartoday;$y<=$yearplus1;$y++){  
           $selected = "";
           $Year = date("Y", mktime(0,0,0,1,1,$y));
           if ($year==$y){ 
            $selected = "selected \n";
           }
           echo "<option value=\"$y\" $selected>$year</option> \n";
         }
?>
</select>
<select id="month3" name="month" value="<?php echo $_SESSION['values']['month']?>">
<?php
$months = Array("Jan", "Feb", "Mar", "Apr", "May",  "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
for ($x=1; $x <= count($months); $x++) {
   echo"<option value=\"$x\"";
   if ($x == $month) {
      echo " selected";
   }
   echo ">".$months[$x-1]."</option>";
}
?>
</select>
<select id="day3" name="day" value="<?php echo $_SESSION['values']['day']?>">
<?php
for ($x= 1; $x<=31; $x++) {
   echo "<option";
   if ($x == $day) {
      echo " selected";
   }
   echo ">$x</option>";
}
?>
</select>
  <p>
  <label id="service">Service:</label><br />
  <select id="serviceSelect" name="service">
   <option value="<?php echo $_SESSION['values']['service']?>">Choose <?=$service_option?>
  </option>
  </select>
  </p>
  <p>
  <label id="unit">Unit:</label><br />
  <input id="radioHour" type = 'Radio' name ='unit' value= 'hour'><label id="Hour">Hour</label>
  <input id="radioDay" type = 'Radio' name ='unit' value= 'day'><label id="Day">Day</label>
  </p> 
<label id="quantity">Quantity:</label><br/>
<select id="quantSelect" name="quantity" value="<?php echo $_SESSION['values']['quantity']?>">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
</select>
<br />
<label id="eventStartTime">Start Time:</label><br/>
<select id="hour" name="start_time_hr" value="<?php echo $_SESSION['values']['start_time_hr']?>">
<option value="09">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
</select>
<select id="minute" name="start_time_min" value="<?php echo $_SESSION['values']['start_time_min']?>">
<option value="00">00</option>
<option value="15">15</option>
<option value="30">30</option>
<option value="45">45</option>
</select></p>
<br />
<label id="extraInfo">Extra Information:</label><br />
<textarea id="extraInfoInput" name="content" value="<?php echo $_SESSION['values']['extra_info']?>" onkeypress="return imposeMaxLength(this, 250);"></textarea>
<p>
<label id="con4">Consultant [1]:</label><br />
<select id="conSelect4" name="con_id1"><option value="<?php echo $_SESSION['values']['con_id1']?>">Choose <?=$consultant_option1?>
</option></select> 
<label id="con2">Consultant [2]:</label><br />
<select id="conSelect2" name="con_id2"><option value="<?php echo $_SESSION['values']['con_id2']?>">Choose <?=$consultant_option2?></option></select> 
<label id="con3">Consultant [3]:</label><br />
<select id="conSelect3" name="con_id3"><option value="<?php echo $_SESSION['values']['con_id3']?>">Choose <?=$consultant_option3?></option></select> 
<input  id= "check1" type ="submit" name="Check" onClick="document.pressed=this.value" value="Check"></p>
<p><input id="book" type ="submit" name="Book" onClick="document.pressed=this.value" value="Book"/></form>
</div>
<div id="copyright">Salmons Reach Consultancy LLP ©, All rights reserved. Any duplication of property or misrepresentation will result in a judicial procedure.<p></div> 
</div>
<div id="rightPanel">
</div>
<div id="sideLogo"> <img src="sideLogo.png"/></div>
</body>
</html>

 

So all gaps are now closed, but still only the day and month remain?

Link to comment
Share on other sites

select boxes don't get a value .. so lose that, ie.

<select id="month3" name="month" value="<?php echo $_SESSION['values']['month']?>">

 

the session var is not get reset?  the select box is not getting reset?

 

is it good that the month and day values are still there? or bad.  get to the point.

 

from what i see, you're not allowing your day and month values in the form to be clear .. month will default to Jan, and day will default to 1.

 

create a dummy option tag to accommodate.

Link to comment
Share on other sites

Its a good thing to keep the values. I just want the user to check availability before booking, so they enter the values, check the availability of dates, times, consultants, and then return to the form with the previously entered data. I am trying to retain the input from page to page, but its only working with the month and day.

Link to comment
Share on other sites

thing is, you're not setting it up properly to allow for the select boxes to be populated.

 

<select> tags do not require values as they do nothing.  perhaps you need to read up on your HTML before continuing.

 

have you echo'd out any of your session values, or checked your source code .. i bet if you check your source, and then check the value="" in your select boxes you'd see that your session vars are being set.

 

<?php
$arrStartTime = array(09,10,11,12,13,14,15,16);
?>
<select id="hour" name="start_time_hr">
<option value="nil">- Make a Selection -</option>
<?php
	foreach($arrStartTime as $value)
	{
		echo '<option value="'.$value.'"'.($value==$_POST['start_time_hr'] ? ' selected="selected"' : '').'>'.$value.'</option>';
	}
?>
</select>

 

try something like that.

Link to comment
Share on other sites

I have just changed it so my "selects" default to a choose option, with no value. Now I will try the next thing that you suggested.

 

This is the code as it stands.

<?php 

  session_start();
  
if (!isset($_SESSION['username']))
    {
header("Location: login.php");
exit();
    }
else if (!isset($_SESSION['values'])){
  $_SESSION['values']['year']=''; 
  $_SESSION['values']['month']=''; 
  $_SESSION['values']['day']=''; 
  $_SESSION['values']['unit']=''; 
  $_SESSION['values']['quantity']=''; 
  $_SESSION['values']['start_time_hr']=''; 
  $_SESSION['values']['start_time_min']=''; 
  $_SESSION['values']['extra_info']=''; 
  $_SESSION['values']['con_id1']=''; 
  $_SESSION['values']['con_id2']=''; 
  $_SESSION['values']['con_id3']=''; 
}
else{
  $_SESSION['values']['year']=$_GET['year']; 
  $_SESSION['values']['month']=$_GET['month']; 
  $_SESSION['values']['day']=$_GET['day']; 
  $_SESSION['values']['unit']=$_GET['unit']; 
  $_SESSION['values']['quantity']=$_GET['quantity']; 
  $_SESSION['values']['start_time_hr']=$_GET['start_time_hr']; 
  $_SESSION['values']['start_time_min']=$_GET['start_time_min']; 
  $_SESSION['values']['extra_info']=$_GET['extra_info']; 
  $_SESSION['values']['con_id1']=$_GET['con_id1']; 
  $_SESSION['values']['con_id2']=$_GET['con_id2']; 
  $_SESSION['values']['con_id3']=$_GET['con_id3']; 
}

  if(isset($_GET['available1']) && $_GET['available1']=='true') {
    echo '<div id="available1true">Available: √</div>';
   }
  if(isset($_GET['available1']) && $_GET['available1']=='false') {
    echo '<div id="available1false">Not Available: X</div>';
   }

  if(isset($_GET['available2']) && $_GET['available2']=='true') {
    echo '<div id="available2true">Available: √</div>';
   }
  if(isset($_GET['available2']) && $_GET['available2']=='false') {
    echo '<div id="available2false">Not Available: X</div>';
   }

if(isset($_GET['available3']) && $_GET['available3']=='true') {
    echo '<div id="available3true">Available: √</div>';
   }
  if(isset($_GET['available3']) && $_GET['available3']=='false') {
    echo '<div id="available3false">Not Available: X</div>';
   }

require "dbconn2.php";

  $sql="SELECT service_id, service FROM service";
  $result=mysql_query($sql);
  $service_option="";
  
while ($row=mysql_fetch_array($result)) {

    $id=$row["service_id"];
    $service=$row["service"];
    $service_option.="<OPTION VALUE=\"$id\">".$service;
}
  $sql="SELECT con_id, first_name, last_name FROM consultant";
  $result=mysql_query($sql);
  $rconsultant_option="";

while ($row=mysql_fetch_array($result)) {

    $con_id=$row["con_id"];
    $first_name=$row["first_name"];
$last_name=$row["last_name"];
    $consultant_option1.="<OPTION VALUE=\"$con_id\">".$first_name." ".$last_name;
$consultant_option2.="<OPTION VALUE=\"$con_id\">".$first_name." ".$last_name;
    $consultant_option3.="<OPTION VALUE=\"$con_id\">".$first_name." ".$last_name;
}

  $yeartoday = date(Y);
  $yearplus1 = date(Y)+1;
  
  for($y=$yeartoday;$y<=$yearplus1;$y++){  
       $selected = "";
       $longDate = date("Y", mktime(0,0,0,1,1,$y));
       if ($Year==$y){ 
       $selected = "selected \n";
        }
        $year_option.="<option value=\"$y\"$selected>$longDate</option>\n";
       }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>SRC: Booking Form</title>
<link href="master.css" rel="stylesheet" type="text/css">
<link rel="shortcut icon" type="image/ico" href="favicon.ico">
<script type="text/javascript">
<!--

function OnSubmitForm()
{
  if(document.pressed == 'Check')
  {
   document.bookingForm.action ="checkavailability1.php";
  }
  else if(document.pressed == 'Book')
  {
    document.bookingForm.action ="book.php";
  }
  return true;
}

//-->
</script>
</head>

<body>

<div id="centerPanel"><div id="header">Booking Form</div><p>
<div id="content">
<form name="bookingForm" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" onSubmit="return OnSubmitForm();">
<label id="eventStart">Event Date:</label><br />
<select id="year3" name="year"><option value="<?php echo $_SESSION['values']['year']?>">Choose <?=$year_option?></option></select> 
<select id="month3" name="month" value="<?php echo $_SESSION['values']['month']?>"/>
<option>Choose</option>
<option value="01">Jan</option>
<option value="02">Feb</option>
<option value="03">Mar</option>
<option value="04">Apr</option>
<option value="05">May</option>
<option value="06">Jun</option>
<option value="07">Jul</option>
<option value="08">Aug</option>
<option value="09">Sep</option>
<option value="10">Oct</option>
<option value="11">Nov</option>
<option value="12">Dec</option>
</select>
<select id="day3" name="day" value="<?php echo $_SESSION['values']['day']?>">
<option>Choose</option>
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
  <p>
  <label id="service">Service:</label><br />
  <select id="serviceSelect" name="service">
   <option value="<?php echo $_SESSION['values']['service']?>">Choose <?=$service_option?>
  </option>
  </select>
  </p>  
  <p>
  <label id="unit">Unit:</label><br />
  <input id="radioHour" type = 'Radio' name ='unit' value="<?php echo $_SESSION['values']['hour']?>"><label id="Hour">Hour</label>
  <input id="radioDay" type = 'Radio' name ='unit' value="<?php echo $_SESSION['values']['day']?>"><label id="Day">Day</label>
  </p>  
<label id="quantity">Quantity:</label><br/>
<select id="quantSelect" name="quantity" value="<?php echo $_SESSION['values']['quantity']?>">
<option>Choose</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
</select>
<br />
<label id="eventStartTime">Start Time:</label><br/>
<select id="hour" name="start_time_hr" value="<?php echo $_SESSION['values']['start_time_hr']?>">
<option>Choose</option>
<option value="09">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
</select>
<select id="minute" name="start_time_min" value="<?php echo $_SESSION['values']['start_time_min']?>">
<option>Choose</option>
<option value="00">00</option>
<option value="15">15</option>
<option value="30">30</option>
<option value="45">45</option>
</select></p>
<br />
<label id="extraInfo">Extra Information:</label><br />
<textarea id="extraInfoInput" name="content" value="<?php echo $_SESSION['values']['extra_info']?>" onkeypress="return imposeMaxLength(this, 250);"></textarea>
<p>
<label id="con4">Consultant [1]:</label><br />
<select id="conSelect4" name="con_id1"><option value="<?php echo $_SESSION['values']['con_id1']?>">Choose <?=$consultant_option1?>
</option></select> 
<label id="con2">Consultant [2]:</label><br />
<select id="conSelect2" name="con_id2"><option value="<?php echo $_SESSION['values']['con_id2']?>">Choose <?=$consultant_option2?></option></select> 
<label id="con3">Consultant [3]:</label><br />
<select id="conSelect3" name="con_id3"><option value="<?php echo $_SESSION['values']['con_id3']?>">Choose <?=$consultant_option3?></option></select> 
<input  id= "check1" type ="submit" name="Check" onClick="document.pressed=this.value" value="Check"></p>
<p><input id="book" type ="submit" name="Book" onClick="document.pressed=this.value" value="Book"/></form>
</div>
</body>
</html>

Link to comment
Share on other sites

i see you still need to lose the value="blah blah" in your <select>'s .. they do nothing.

 

the <select>'s get a name, and the <option>'s get a value.

 

notice my latest post with the updated array .. get it working, then you can mess around with the array values (if need be), to change the output.

Link to comment
Share on other sites

I have changed all the selects, so how can I get the values stored in the session, and retrieved when the user returns to the form?

 

<?php 

  session_start();
  
if (!isset($_SESSION['username']))
    {
header("Location: login.php");
exit();
    }
else if (!isset($_SESSION['values'])){
  $_SESSION['values']['year']=''; 
  $_SESSION['values']['month']=''; 
  $_SESSION['values']['day']=''; 
  $_SESSION['values']['unit']=''; 
  $_SESSION['values']['quantity']=''; 
  $_SESSION['values']['start_time_hr']=''; 
  $_SESSION['values']['start_time_min']=''; 
  $_SESSION['values']['extra_info']=''; 
  $_SESSION['values']['con_id1']=''; 
  $_SESSION['values']['con_id2']=''; 
  $_SESSION['values']['con_id3']=''; 
}
else{
  $_SESSION['values']['year']=$_GET['year']; 
  $_SESSION['values']['month']=$_GET['month']; 
  $_SESSION['values']['day']=$_GET['day']; 
  $_SESSION['values']['unit']=$_GET['unit']; 
  $_SESSION['values']['quantity']=$_GET['quantity']; 
  $_SESSION['values']['start_time_hr']=$_GET['start_time_hr']; 
  $_SESSION['values']['start_time_min']=$_GET['start_time_min']; 
  $_SESSION['values']['extra_info']=$_GET['extra_info']; 
  $_SESSION['values']['con_id1']=$_GET['con_id1']; 
  $_SESSION['values']['con_id2']=$_GET['con_id2']; 
  $_SESSION['values']['con_id3']=$_GET['con_id3']; 
}

  if(isset($_GET['available1']) && $_GET['available1']=='true') {
    echo '<div id="available1true">Available: √</div>';
   }
  if(isset($_GET['available1']) && $_GET['available1']=='false') {
    echo '<div id="available1false">Not Available: X</div>';
   }

  if(isset($_GET['available2']) && $_GET['available2']=='true') {
    echo '<div id="available2true">Available: √</div>';
   }
  if(isset($_GET['available2']) && $_GET['available2']=='false') {
    echo '<div id="available2false">Not Available: X</div>';
   }

if(isset($_GET['available3']) && $_GET['available3']=='true') {
    echo '<div id="available3true">Available: √</div>';
   }
  if(isset($_GET['available3']) && $_GET['available3']=='false') {
    echo '<div id="available3false">Not Available: X</div>';
   }

require "dbconn2.php";

  $sql="SELECT service_id, service FROM service";
  $result=mysql_query($sql);
  $service_option="";
  
while ($row=mysql_fetch_array($result)) {

    $id=$row["service_id"];
    $service=$row["service"];
    $service_option.="<OPTION VALUE=\"$id\">".$service;
}
  $sql="SELECT con_id, first_name, last_name FROM consultant";
  $result=mysql_query($sql);
  $rconsultant_option="";

while ($row=mysql_fetch_array($result)) {

    $con_id=$row["con_id"];
    $first_name=$row["first_name"];
$last_name=$row["last_name"];
    $consultant_option1.="<OPTION VALUE=\"$con_id\">".$first_name." ".$last_name;
$consultant_option2.="<OPTION VALUE=\"$con_id\">".$first_name." ".$last_name;
    $consultant_option3.="<OPTION VALUE=\"$con_id\">".$first_name." ".$last_name;
}

  $yeartoday = date(Y);
  $yearplus1 = date(Y)+1;
  
  for($y=$yeartoday;$y<=$yearplus1;$y++){  
       $selected = "";
       $longDate = date("Y", mktime(0,0,0,1,1,$y));
       if ($Year==$y){ 
       $selected = "selected \n";
        }
        $year_option.="<option value=\"$y\"$selected>$longDate</option>\n";
       }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>SRC: Booking Form</title>
<link href="master.css" rel="stylesheet" type="text/css">
<link rel="shortcut icon" type="image/ico" href="favicon.ico">
<script type="text/javascript">
<!--

function OnSubmitForm()
{
  if(document.pressed == 'Check')
  {
   document.bookingForm.action ="checkavailability1.php";
  }
  else if(document.pressed == 'Book')
  {
    document.bookingForm.action ="book.php";
  }
  return true;
}

//-->
</script>
</head>

<body>
<div id="topbanner"><h1>Salmons Reach Consultancy</h1><h2>Striving to achieve excellence</h2></div><div id="salmon"><img src="Salmon.png" /></div>
<div id="loginRegister">
<a id="location" href="">Login </a>|  <a href="register.php">Register</a>
</div>
<div id="border">
</div>
<div id="quickLinks">
<ul><p>
      <li id="Title">QUICK LINKS</li><p>
      <li id="Title1"><a href="index.php"><b>HOME</b></a></li>
      <li><a href="work.php">Work</a></li>
      <li><a href="play.php">Play</a></li>
      <li><a href="future.php">Future</a></li>
      <li><a href="present.php">Present</a></li><p>
      <li id="Title1"><a href="history.php"><b>HISTORY</b></a></li>
      <li><a href="past.php">Past</a></li>
      <li><a href="staff.php">Staff</a></li>
      <li><a href="direction.php">Direction</a></li>
      <li><a href="destination.php">Destination</a></li><p>
      <li id="Title1"><a href="portfolio.php"><b>PORTFOLIO</b></a></li>
      <li><a href="thurrock.php">Thurrock</a></li>
      <li><a href="aru.php">Anglia Ruskin University</a></li>
      <li><a href="stgeorges.php">St Georges</a></li>
      <li><a href="malaysia.php">Malaysia</a></li><p>
      <li id="Title1"><a href="services.php"><b>SERVICES</b></a></li>
      <li><a href="consultancy.php">Consultancy</a></li>
      <li><a href="pd.php">Personal Development</a></li>
      <li><a href="project.php">Project Guidance and Initiation</a></li>
      <li><a href="od.php">Organisational Development</a></li><p>
      <li id="Title1"><a href="contact.php"><b>CONTACT</b></a></li>
      <li><a href="technical.php">Technical Support</a></li>
      <li><a href="regInterest.php">Register Interest For Services</a></li>
      <li><a href="message.php">Message Consultant</a></li><p>
</ul>
</div>
<div id="menu">
<ul>
  <li><input id="button1" type="button" value="Home" onclick="parent.location = 'index.php'" />
     <ul>
      <li><a href="work.php">[Work]</a></li>
      <li><a href="play.php">[Play]</a></li>
      <li><a href="future.php">[Future]</a></li>
      <li><a href="present.php">[Present]</a></li>
    </ul>
  </li>
  <li><input id="button2" type="button" onclick="parent.location = 'history.php'" value="History" />
    <ul>
      <li><a href="past.php">[Past]</a></li>
      <li><a href="staff.php">[staff]</a></li>
      <li><a href="direction.php">[Direction]</a></li>
      <li><a href="destination.php">[Destination]</a></li>
    </ul>
  </li>
    <li><input id="button3" type="button" onclick="parent.location = 'portfolio.php'" value="Portfolio" />
    <ul>
      <li><a href="thurrock.php">[Thurrock]</a></li>
      <li><a href="aru.php">[Anglia Ruskin University]</a></li>
      <li><a href="stgeorges.php">[st Georges]</a></li>
      <li><a href="malaysia.php">[Malaysia]</a></li>
    </ul>
  </li>
    <li><input id="button4" type="button" onclick="parent.location = 'services.php'" value="Services" />
    <ul>
      <li><a href="consultancy.php">[Consultancy]</a></li>
      <li><a href="pd.php">[Personal Development]</a></li>
      <li><a href="project.php">[Project Guidance and Initiation]</a></li>
      <li><a href="od.php">[Organisational Development]</a></li>
    </ul>
  </li>	
    <li><input id="button5" type="button" onclick="parent.location = 'contact.php'" value="contact" />
    <ul>
      <li><a href="technical.php">[Technical Support]</a></li>
      <li><a href="regInterest.php">[Register Interest For Services]</a></li>
      <li><a href="message.php">[Message Consultant]</a></li>
    </ul>
  </li>
  <li><input id="button5" type="button" value="Back" onClick="history.go(-1)">
  </li>
</ul>
</div>
</div><div id="centerPanel1">
</div>
<div id="rightPanel1">
</div>
<div id="centerPanel"><div id="header">Booking Form</div><p>
<div id="content">
<form name="bookingForm" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" onSubmit="return OnSubmitForm();">

<label id="eventStart">Event Date:</label><br />
<select id="year3" name="year"><option value="<?php echo $_SESSION['values']['year']?>">Choose <?=$year_option?></option></select> 

<?php
$arrMonth = array('01','02','03','04','05','06','07','08','09','10','11','12');
?>
<select id="month3" name="month">
   <option value="nil">Choose</option>
   <?php
      foreach($arrMonth as $value)
      {
         echo '<option value="'.$value.'"'.($value==$_POST['month'] ? ' selected="selected"' : '').'>'.$value.'</option>';
      }
   ?>

<?php
$arrDay = array('01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31');
?>
<select id="day3" name="day">
   <option value="nil">Choose</option>
   <?php
      foreach($arrDay as $value)
      {
         echo '<option value="'.$value.'"'.($value==$_POST['day'] ? ' selected="selected"' : '').'>'.$value.'</option>';
      }
   ?>
</select>

  <label id="service">Service:</label><br />
  <select id="serviceSelect" name="service">
   <option value="<?php echo $_SESSION['values']['service']?>">Choose <?=$service_option?>
  </option>
  </select>
  </p>
  
  <p>
  <label id="unit">Unit:</label><br />
  <input id="radioHour" type = 'Radio' name ='unit' value="<?php echo $_SESSION['values']['hour']?>"><label id="Hour">Hour</label>
  <input id="radioDay" type = 'Radio' name ='unit' value="<?php echo $_SESSION['values']['day']?>"><label id="Day">Day</label>
  </p>
  
<label id="quantity">Quantity:</label><br/>
<?php
$arrQuant = array('01','02','03','04','05','06','07');
?>
<select id="quantSelect" name="quantity">
   <option value="nil">Choose</option>
   <?php
      foreach($arrQuant as $value)
      {
         echo '<option value="'.$value.'"'.($value==$_POST['quantity'] ? ' selected="selected"' : '').'>'.$value.'</option>';
      }
   ?>
</select>

<label id="eventStartTime">Start Time:</label><br/>
<?php
$arrStartTimeHr = array('09','10','11','12','13','14','15','16');
?>
<select id="hour" name="start_time_hr">
   <option value="nil">Choose</option>
   <?php
      foreach($arrStartTimeHr as $value)
      {
         echo '<option value="'.$value.'"'.($value==$_POST['start_time_hr'] ? ' selected="selected"' : '').'>'.$value.'</option>';
      }
   ?>
</select>

<?php
$arrStartTimeMin = array('00','15','30','45');
?>
<select id="minute" name="start_time_min">
   <option value="nil">Choose</option>
   <?php
      foreach($arrStartTimeMin as $value)
      {
         echo '<option value="'.$value.'"'.($value==$_POST['start_time_Min'] ? ' selected="selected"' : '').'>'.$value.'</option>';
      }
   ?>
</select>

<label id="extraInfo">Extra Information:</label><br />
<textarea id="extraInfoInput" name="content" value="<?php echo $_SESSION['values']['extra_info']?>" onkeypress="return imposeMaxLength(this, 250);"></textarea>

<p>
<label id="con4">Consultant [1]:</label><br />
<select id="conSelect4" name="con_id1"><option value="<?php echo $_SESSION['values']['con_id1']?>">Choose <?=$consultant_option1?>
</option></select> 

<label id="con2">Consultant [2]:</label><br />
<select id="conSelect2" name="con_id2"><option value="<?php echo $_SESSION['values']['con_id2']?>">Choose <?=$consultant_option2?></option></select> 

<label id="con3">Consultant [3]:</label><br />
<select id="conSelect3" name="con_id3"><option value="<?php echo $_SESSION['values']['con_id3']?>">Choose <?=$consultant_option3?></option></select> 

<input  id= "check1" type ="submit" name="Check" onClick="document.pressed=this.value" value="Check"></p>
<p><input id="book" type ="submit" name="Book" onClick="document.pressed=this.value" value="Book"/></form>
</div>
<div id="copyright">Salmons Reach Consultancy LLP ©, All rights reserved. Any duplication of property or misrepresentation will result in a judicial procedure.<p></div> 
</div>
<div id="rightPanel">
</div>
<div id="sideLogo"> <img src="sideLogo.png"/></div>

</body>
</html>

Link to comment
Share on other sites

Sorry I forgot to change the GET (session var) to POST, now that is corrected:

<?php 

  session_start();
  
if (!isset($_SESSION['username']))
    {
header("Location: login.php");
exit();
    }
else if (!isset($_SESSION['values'])){
  $_SESSION['values']['year']=''; 
  $_SESSION['values']['month']=''; 
  $_SESSION['values']['day']=''; 
  $_SESSION['values']['unit']=''; 
  $_SESSION['values']['quantity']=''; 
  $_SESSION['values']['start_time_hr']=''; 
  $_SESSION['values']['start_time_min']=''; 
  $_SESSION['values']['extra_info']=''; 
  $_SESSION['values']['con_id1']=''; 
  $_SESSION['values']['con_id2']=''; 
  $_SESSION['values']['con_id3']=''; 
}
else{
  $_SESSION['values']['year']=$_POST['year']; 
  $_SESSION['values']['month']=$_POST['month']; 
  $_SESSION['values']['day']=$_POST['day']; 
  $_SESSION['values']['unit']=$_POST['unit']; 
  $_SESSION['values']['quantity']=$_POST['quantity']; 
  $_SESSION['values']['start_time_hr']=$_POST['start_time_hr']; 
  $_SESSION['values']['start_time_min']=$_POST['start_time_min']; 
  $_SESSION['values']['extra_info']=$_POST['extra_info']; 
  $_SESSION['values']['con_id1']=$_POST['con_id1']; 
  $_SESSION['values']['con_id2']=$_POST['con_id2']; 
  $_SESSION['values']['con_id3']=$_POST['con_id3']; 
}

  if(isset($_GET['available1']) && $_GET['available1']=='true') {
    echo '<div id="available1true">Available: √</div>';
   }
  if(isset($_GET['available1']) && $_GET['available1']=='false') {
    echo '<div id="available1false">Not Available: X</div>';
   }

  if(isset($_GET['available2']) && $_GET['available2']=='true') {
    echo '<div id="available2true">Available: √</div>';
   }
  if(isset($_GET['available2']) && $_GET['available2']=='false') {
    echo '<div id="available2false">Not Available: X</div>';
   }

if(isset($_GET['available3']) && $_GET['available3']=='true') {
    echo '<div id="available3true">Available: √</div>';
   }
  if(isset($_GET['available3']) && $_GET['available3']=='false') {
    echo '<div id="available3false">Not Available: X</div>';
   }

require "dbconn2.php";

  $sql="SELECT service_id, service FROM service";
  $result=mysql_query($sql);
  $service_option="";
  
while ($row=mysql_fetch_array($result)) {

    $id=$row["service_id"];
    $service=$row["service"];
    $service_option.="<OPTION VALUE=\"$id\">".$service;
}
  $sql="SELECT con_id, first_name, last_name FROM consultant";
  $result=mysql_query($sql);
  $rconsultant_option="";

while ($row=mysql_fetch_array($result)) {

    $con_id=$row["con_id"];
    $first_name=$row["first_name"];
$last_name=$row["last_name"];
    $consultant_option1.="<OPTION VALUE=\"$con_id\">".$first_name." ".$last_name;
$consultant_option2.="<OPTION VALUE=\"$con_id\">".$first_name." ".$last_name;
    $consultant_option3.="<OPTION VALUE=\"$con_id\">".$first_name." ".$last_name;
}

  $yeartoday = date(Y);
  $yearplus1 = date(Y)+1;
  
  for($y=$yeartoday;$y<=$yearplus1;$y++){  
       $selected = "";
       $longDate = date("Y", mktime(0,0,0,1,1,$y));
       if ($Year==$y){ 
       $selected = "selected \n";
        }
        $year_option.="<option value=\"$y\"$selected>$longDate</option>\n";
       }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>SRC: Booking Form</title>
<link href="master.css" rel="stylesheet" type="text/css">
<link rel="shortcut icon" type="image/ico" href="favicon.ico">
<script type="text/javascript">
<!--

function OnSubmitForm()
{
  if(document.pressed == 'Check')
  {
   document.bookingForm.action ="checkavailability1.php";
  }
  else if(document.pressed == 'Book')
  {
    document.bookingForm.action ="book.php";
  }
  return true;
}

//-->
</script>
</head>

<body>
<div id="content">
<form name="bookingForm" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" onSubmit="return OnSubmitForm();">

<label id="eventStart">Event Date:</label><br />
<select id="year3" name="year"><option value="<?php echo $_SESSION['values']['year']?>">Choose <?=$year_option?></option></select> 

<?php
$arrMonth = array('01','02','03','04','05','06','07','08','09','10','11','12');
?>
<select id="month3" name="month">
   <option value="nil">Choose</option>
   <?php
      foreach($arrMonth as $value)
      {
         echo '<option value="'.$value.'"'.($value==$_POST['month'] ? ' selected="selected"' : '').'>'.$value.'</option>';
      }
   ?>

<?php
$arrDay = array('01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31');
?>
<select id="day3" name="day">
   <option value="nil">Choose</option>
   <?php
      foreach($arrDay as $value)
      {
         echo '<option value="'.$value.'"'.($value==$_POST['day'] ? ' selected="selected"' : '').'>'.$value.'</option>';
      }
   ?>
</select>

  <label id="service">Service:</label><br />
  <select id="serviceSelect" name="service">
   <option value="<?php echo $_SESSION['values']['service']?>">Choose <?=$service_option?>
  </option>
  </select>
  </p>
  
  <p>
  <label id="unit">Unit:</label><br />
  <input id="radioHour" type = 'Radio' name ='unit' value="<?php echo $_SESSION['values']['hour']?>"><label id="Hour">Hour</label>
  <input id="radioDay" type = 'Radio' name ='unit' value="<?php echo $_SESSION['values']['day']?>"><label id="Day">Day</label>
  </p>
  
<label id="quantity">Quantity:</label><br/>
<?php
$arrQuant = array('01','02','03','04','05','06','07');
?>
<select id="quantSelect" name="quantity">
   <option value="nil">Choose</option>
   <?php
      foreach($arrQuant as $value)
      {
         echo '<option value="'.$value.'"'.($value==$_POST['quantity'] ? ' selected="selected"' : '').'>'.$value.'</option>';
      }
   ?>
</select>

<label id="eventStartTime">Start Time:</label><br/>
<?php
$arrStartTimeHr = array('09','10','11','12','13','14','15','16');
?>
<select id="hour" name="start_time_hr">
   <option value="nil">Choose</option>
   <?php
      foreach($arrStartTimeHr as $value)
      {
         echo '<option value="'.$value.'"'.($value==$_POST['start_time_hr'] ? ' selected="selected"' : '').'>'.$value.'</option>';
      }
   ?>
</select>

<?php
$arrStartTimeMin = array('00','15','30','45');
?>
<select id="minute" name="start_time_min">
   <option value="nil">Choose</option>
   <?php
      foreach($arrStartTimeMin as $value)
      {
         echo '<option value="'.$value.'"'.($value==$_POST['start_time_Min'] ? ' selected="selected"' : '').'>'.$value.'</option>';
      }
   ?>
</select>

<label id="extraInfo">Extra Information:</label><br />
<textarea id="extraInfoInput" name="content" value="<?php echo $_SESSION['values']['extra_info']?>" onkeypress="return imposeMaxLength(this, 250);"></textarea>

<p>
<label id="con4">Consultant [1]:</label><br />
<select id="conSelect4" name="con_id1"><option value="<?php echo $_SESSION['values']['con_id1']?>">Choose <?=$consultant_option1?>
</option></select> 

<label id="con2">Consultant [2]:</label><br />
<select id="conSelect2" name="con_id2"><option value="<?php echo $_SESSION['values']['con_id2']?>">Choose <?=$consultant_option2?></option></select> 

<label id="con3">Consultant [3]:</label><br />
<select id="conSelect3" name="con_id3"><option value="<?php echo $_SESSION['values']['con_id3']?>">Choose <?=$consultant_option3?></option></select> 

<input  id= "check1" type ="submit" name="Check" onClick="document.pressed=this.value" value="Check"></p>
<p><input id="book" type ="submit" name="Book" onClick="document.pressed=this.value" value="Book"/></form>
</div>
</body>
</html>

Link to comment
Share on other sites

you need to figure out whether you're using $_POST or $_GET here .. you form method is POST, but your vars are GET.

 

i'll help ya out with populating the options and such, but you gotta straighten all the other inconsistencies floating around.

 

for example, your textarea's have value attributes .. that doesn't work .. this is how textarea's work .. <textarea name="something">stuff here...</textarea>.

 

i'm thinking you should reconsider your structure, ie. have the availability checked either through AJAX, or before the user even gets the form .. or just have a pop-up box showing availability.

 

you might be getting ahead of yourself by the looks of it, otherwise.

Link to comment
Share on other sites

I have changed that now. I would rethink the structure however it is for my final year project at uni and I only have 4 weeks to go, so its a bit tight to start learning AJAX, its taken me 2 months to learn PHP to my present standard which appears to be pretty low. So I have got this script from my lecturer and I need to tie it in some how:

sessionIndex.php

<?php
session_start();
?>
<html>
<title>Using Session Data to Populate a Form</title>
<body>
<form action='sessionReceiver.php' method='post'>
<table border='0' cellpadding='3' cellspacing='0'>
  <tr>
    <td>First Name</td>
    <td>
      <input type='text' size='40' name='firstName' value='<?php if (isset($_SESSION['firstName'])) echo $_SESSION['firstName']; ?>' />
    </td>
  </tr>
  <tr>
    <td>Last Name</td>
    <td>
      <input type='text' size='40' name='lastName' value='<?php if (isset($_SESSION['lastName'])) echo $_SESSION['lastName']; ?>' />
    </td>
  </tr>
    <td><input type='reset' value='  Reset  ' /></td>
    <td><input type='submit' value='  Send  ' /></td>
  </tr>
</table>
</form>
</body>
</html>

sessionReceiver.php

<?php
session_start();
?>
<html>
<title>Saving Session Data</title>
<body>
  <h3>Saving Session Data</h3>
<?php
$saved = array();

if (isset($_POST['firstName']) && strlen($_POST['firstName']) > 0)
{
	$_SESSION['firstName'] = $_POST['firstName'];

	$saved[] = 'first name ('.$_POST['firstName'].')';
}

if (isset($_POST['lastName']) && strlen($_POST['lastName']) > 0)
{
	$_SESSION['lastName'] = $_POST['lastName'];

	$saved[] = 'last name ('.$_POST['lastName'].')';
}

if (count($saved) == 0)
{
	echo "<p>No session data saved</p>\r\n";
}
else
{
	echo "<p>The following session data saved: ".implode(', ', $saved)."</p>\r\n";
}
?>
  <p><a href='sessionIndex.php'>Go back to session index page</a></p>
</body>
</html>

 

Here it is in action:http://www.salmonsreach.org/database/sessionIndex.php

 

The form retains the input from the SESSION, this is what I want my form to do.

Link to comment
Share on other sites

Now I have my SESSION vars being passed from page to page, but how do I use them to populate my form? ???

 

bookingForm.php

<?php  
  session_start();
  
if (!isset($_SESSION['username']))
    {
header("Location: login.php");
exit();
    }
else if (!isset($_SESSION['values'])){
  $_SESSION['values']['year']='';
  $_SESSION['values']['month']=''; 
  $_SESSION['values']['day']=''; 
  $_SESSION['values']['service']=''; 
  $_SESSION['values']['unit']=''; 
  $_SESSION['values']['quantity']=''; 
  $_SESSION['values']['start_time_hr']=''; 
  $_SESSION['values']['start_time_min']=''; 
  $_SESSION['values']['extra_info']=''; 
  $_SESSION['values']['con_id1']=''; 
  $_SESSION['values']['con_id2']=''; 
  $_SESSION['values']['con_id3']=''; 
}
else{ 
  $_SESSION['values']['year']=$_POST['year']; 
  $_SESSION['values']['month']=$_POST['month']; 
  $_SESSION['values']['day']=$_POST['day'];
  $_SESSION['values']['service']=$_POST['service']; 
  $_SESSION['values']['unit']=$_POST['unit']; 
  $_SESSION['values']['quantity']=$_POST['quantity']; 
  $_SESSION['values']['start_time_hr']=$_POST['start_time_hr']; 
  $_SESSION['values']['start_time_min']=$_POST['start_time_min']; 
  $_SESSION['values']['extra_info']=$_POST['extra_info']; 
  $_SESSION['values']['con_id1']=$_POST['con_id1']; 
  $_SESSION['values']['con_id2']=$_POST['con_id2']; 
  $_SESSION['values']['con_id3']=$_POST['con_id3']; 
}

  if(isset($_GET['available1']) && $_GET['available1']=='true') {
    echo '<div id="available1true">Available: √</div>';
   }
  if(isset($_GET['available1']) && $_GET['available1']=='false') {
    echo '<div id="available1false">Not Available: X</div>';
   }

  if(isset($_GET['available2']) && $_GET['available2']=='true') {
    echo '<div id="available2true">Available: √</div>';
   }
  if(isset($_GET['available2']) && $_GET['available2']=='false') {
    echo '<div id="available2false">Not Available: X</div>';
   }

if(isset($_GET['available3']) && $_GET['available3']=='true') {
    echo '<div id="available3true">Available: √</div>';
   }
  if(isset($_GET['available3']) && $_GET['available3']=='false') {
    echo '<div id="available3false">Not Available: X</div>';
   }

require "dbconn2.php";

  $sql="SELECT service_id, service FROM service";
  $result=mysql_query($sql);
  $service_option="";
  
while ($row=mysql_fetch_array($result)) {

    $id=$row["service_id"];
    $service=$row["service"];
    $service_option.="<OPTION VALUE=\"$id\">".$service;
}
  $sql="SELECT con_id, first_name, last_name FROM consultant";
  $result=mysql_query($sql);
  $rconsultant_option="";

while ($row=mysql_fetch_array($result)) {

    $con_id1=$row["con_id"];
$con_id2=$row["con_id"];
    $con_id3=$row["con_id"];
    $first_name=$row["first_name"];
$last_name=$row["last_name"];
    $consultant_option1.="<OPTION VALUE=\"$con_id1\">".$first_name." ".$last_name;
$consultant_option2.="<OPTION VALUE=\"$con_id2\">".$first_name." ".$last_name;
    $consultant_option3.="<OPTION VALUE=\"$con_id3\">".$first_name." ".$last_name;
}

  $yeartoday = date(Y);
  $yearplus1 = date(Y)+1;
  
  for($y=$yeartoday;$y<=$yearplus1;$y++){  
       $selected = "";
       $longDate = date("Y", mktime(0,0,0,1,1,$y));
       if ($Year==$y){ 
       $selected = "selected \n";
        }
        $year_option.="<option value=\"$y\"$selected>$longDate</option>\n";
        }

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>SRC: Booking Form</title>
<link href="master.css" rel="stylesheet" type="text/css">
<link rel="shortcut icon" type="image/ico" href="favicon.ico">
<script type="text/javascript">
<!--

function OnSubmitForm()
{
  if(document.pressed == 'Check')
  {
   document.bookingForm.action ="checkavailability1.php";
  }
  else if(document.pressed == 'Book')
  {
    document.bookingForm.action ="book.php";
  }
  return true;
}

//-->
</script>
</head>

<body>

<div id="content">
<form name="bookingForm" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" onSubmit="return OnSubmitForm();">

<label id="eventStart">Event Date:</label><br />
<select id="year3" name="year"><option value="<?php $_POST['year']; ?>">Year <?=$year_option?></option></select> 

<?php
$arrMonth = array('01','02','03','04','05','06','07','08','09','10','11','12');
?>
<select id="month3" name="month">
   <option value="nil">Month</option>
   <?php
      foreach($arrMonth as $value)
      {
         echo '<option value="'.$value.'"'.($value==$_POST['month'] ? ' selected="selected"' : '').'>'.$value.'</option>';
      }
   ?>

<?php
$arrDay = array('01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31');
?>
<select id="day3" name="day">
   <option value="nil">Day</option>
   <?php
      foreach($arrDay as $value)
      {
         echo '<option value="'.$value.'"'.($value==$_POST['day'] ? ' selected="selected"' : '').'>'.$value.'</option>';
      }
   ?>
</select>

  <label id="service">Service:</label><br />
  <select id="serviceSelect" name="service">
   <option value="<?php $_POST['service']; ?>">Service<?=$service_option?>
  </option>
  </select>
  </p>
  
  <p>
  <label id="unit">Unit:</label><br />
<?php
$arrUnit = array('Day','Hour');
?>
<select id="radioHour" name="unit">
   <option value="nil">Unit</option>
   <?php
      foreach($arrUnit as $value)
      {
         echo '<option value="'.$value.'"'.($value==$_POST['unit'] ? ' selected="selected"' : '').'>'.$value.'</option>';
      }
   ?>
  
<label id="quantity">Quantity:</label>
<?php
$arrQuant = array('01','02','03','04','05','06','07');
?>
<select id="quantSelect" name="quantity">
   <option value="nil">[00]</option>
   <?php
      foreach($arrQuant as $value)
      {
         echo '<option value="'.$value.'"'.($value==$_POST['quantity'] ? ' selected="selected"' : '').'>'.$value.'</option>';
      }
   ?>
</select>

<label id="eventStartTime">Start Time:</label><br/>
<?php
$arrStartTimeHr = array('09','10','11','12','13','14','15','16');
?>
<select id="hour" name="start_time_hr">
   <option value="nil">Hr</option>
   <?php
      foreach($arrStartTimeHr as $value)
      {
         echo '<option value="'.$value.'"'.($value==$_POST['start_time_hr'] ? ' selected="selected"' : '').'>'.$value.'</option>';
      }
   ?>
</select>

<?php
$arrStartTimeMin = array('00','15','30','45');
?>
<select id="minute" name="start_time_min">
   <option value="nil">Min</option>
   <?php
      foreach($arrStartTimeMin as $value)
      {
         echo '<option value="'.$value.'"'.($value==$_POST['start_time_min'] ? ' selected="selected"' : '').'>'.$value.'</option>';
      }
   ?>
</select>

<label id="extraInfo">Extra Information:</label><br />
<textarea id="extraInfoInput" name="extra_info" value="<?php $_POST['extra_info']; ?>" onkeypress="return imposeMaxLength(this, 250);"></textarea>

<p>
<label id="con4">Consultant [1]:</label><br />
<select id="conSelect4" name="con_id1"><option value="<?php $_POST['con_id1']; ?>">Select<?=$consultant_option1?></select>

<label id="con2">Consultant [2]:</label><br />
<select id="conSelect2" name="con_id2"><option value="<?php $_POST['con_id2']; ?>">Select<?=$consultant_option2?></select>


<label id="con3">Consultant [3]:</label><br />
<select id="conSelect3" name="con_id3"><option value="<?php $_POST['con_id3']; ?>">Select<?=$consultant_option3?></select>


<input  id= "check1" type ="submit" name="Check" onClick="document.pressed=this.value" value="Check"></p>
<p><input id="book" type ="submit" name="Book" onClick="document.pressed=this.value" value="Book"/></form>
</div>
</body>
</html>

checkAvailability.php:

<?php

  session_start();
  
if (!isset($_SESSION['username']))
    {
header("Location: login.php");
exit();
    }
else if (!isset($_SESSION['values'])){
  $_SESSION['values']['year']='';
  $_SESSION['values']['month']=''; 
  $_SESSION['values']['day']=''; 
  $_SESSION['values']['service']=''; 
  $_SESSION['values']['unit']=''; 
  $_SESSION['values']['quantity']=''; 
  $_SESSION['values']['start_time_hr']=''; 
  $_SESSION['values']['start_time_min']=''; 
  $_SESSION['values']['extra_info']=''; 
  $_SESSION['values']['con_id1']=''; 
  $_SESSION['values']['con_id2']=''; 
  $_SESSION['values']['con_id3']=''; 
}
else{ 
  $_SESSION['values']['year']=$_POST['year']; 
  $_SESSION['values']['month']=$_POST['month']; 
  $_SESSION['values']['day']=$_POST['day'];
  $_SESSION['values']['service']=$_POST['service']; 
  $_SESSION['values']['unit']=$_POST['unit']; 
  $_SESSION['values']['quantity']=$_POST['quantity']; 
  $_SESSION['values']['start_time_hr']=$_POST['start_time_hr']; 
  $_SESSION['values']['start_time_min']=$_POST['start_time_min']; 
  $_SESSION['values']['extra_info']=$_POST['extra_info']; 
  $_SESSION['values']['con_id1']=$_POST['con_id1']; 
  $_SESSION['values']['con_id2']=$_POST['con_id2']; 
  $_SESSION['values']['con_id3']=$_POST['con_id3']; 
}


  require "dbconn2.php";
  
  $month = mysql_real_escape_string($_POST["month"]);
  $day =  mysql_real_escape_string($_POST["day"]);
  $year=  mysql_real_escape_string($_POST["year"]);
  $con_id1=  mysql_real_escape_string($_POST["con_id1"]);
  $con_id2=  mysql_real_escape_string($_POST["con_id2"]); 
  $con_id3=  mysql_real_escape_string($_POST["con_id3"]); 
  
  $event_start = $year."-".$month."-".$day." ".$_POST["event_start"];

  if ($con_id1 != null){
  $sql = "SELECT * FROM calendar_events WHERE event_start='".$event_start."' AND (con_1='".$con_id1."' OR con_2='".$con_id1."' OR con_3='".$con_id1."')";

   $result = mysql_query ($sql, $connection) or die ("Could not perform query $sql <br />".mysql_error());
   $row = mysql_fetch_array($result);

if ($row != null){
      $available1 = "false";
  }
  else {
  $available1 = "true";
  }
  }
  if ($con_id2 != null){
  $sql = "SELECT * FROM calendar_events WHERE event_start='".$event_start."' AND (con_1='".$con_id2."' OR con_2='".$con_id2."' OR con_3='".$con_id2."')";

   $result = mysql_query ($sql, $connection) or die ("Could not perform query $sql <br />".mysql_error());
   $row = mysql_fetch_array($result);

if ($row != null){
      $available2 = "false";
  }
  else {
  $available2 = "true";
  }
  }
  if ($con_id3 != null){
  $sql = "SELECT * FROM calendar_events WHERE event_start='".$event_start."' AND (con_1='".$con_id3."' OR con_2='".$con_id3."' OR con_3='".$con_id3."')";

   $result = mysql_query ($sql, $connection) or die ("Could not perform query $sql <br />".mysql_error());
   $row = mysql_fetch_array($result);

if ($row != null){
      $available3 = "false";
  }
  else {
  $available3 = "true";
  }
  }

$url = "Location: bookingform.php?available1=$available1&available2=$available2&available3=$available3";
      header($url);
?>

<html>
<head>
<title>Check Availability</title>
</head>
<body>
</body>
</html>

Link to comment
Share on other sites

Like this?

<?php

  session_start();
  
if (!isset($_SESSION['username']))
    {
header("Location: login.php");
exit();
    }
else if (!isset($_SESSION['values'])){
  $_SESSION['values']['year']='';
  $_SESSION['values']['month']=''; 
  $_SESSION['values']['day']=''; 
  $_SESSION['values']['service']=''; 
  $_SESSION['values']['unit']=''; 
  $_SESSION['values']['quantity']=''; 
  $_SESSION['values']['start_time_hr']=''; 
  $_SESSION['values']['start_time_min']=''; 
  $_SESSION['values']['extra_info']=''; 
  $_SESSION['values']['con_id1']=''; 
  $_SESSION['values']['con_id2']=''; 
  $_SESSION['values']['con_id3']=''; 
}
else{ 
  $_SESSION['values']['year']=$_POST['year']; 
  $_SESSION['values']['month']=$_POST['month']; 
  $_SESSION['values']['day']=$_POST['day'];
  $_SESSION['values']['service']=$_POST['service']; 
  $_SESSION['values']['unit']=$_POST['unit']; 
  $_SESSION['values']['quantity']=$_POST['quantity']; 
  $_SESSION['values']['start_time_hr']=$_POST['start_time_hr']; 
  $_SESSION['values']['start_time_min']=$_POST['start_time_min']; 
  $_SESSION['values']['extra_info']=$_POST['extra_info']; 
  $_SESSION['values']['con_id1']=$_POST['con_id1']; 
  $_SESSION['values']['con_id2']=$_POST['con_id2']; 
  $_SESSION['values']['con_id3']=$_POST['con_id3']; 
}

  if(isset($_GET['available1']) && $_GET['available1']=='true') {
    echo '<div id="available1true">Available: √</div>';
   }
  if(isset($_GET['available1']) && $_GET['available1']=='false') {
    echo '<div id="available1false">Not Available: X</div>';
   }

  if(isset($_GET['available2']) && $_GET['available2']=='true') {
    echo '<div id="available2true">Available: √</div>';
   }
  if(isset($_GET['available2']) && $_GET['available2']=='false') {
    echo '<div id="available2false">Not Available: X</div>';
   }

if(isset($_GET['available3']) && $_GET['available3']=='true') {
    echo '<div id="available3true">Available: √</div>';
   }
  if(isset($_GET['available3']) && $_GET['available3']=='false') {
    echo '<div id="available3false">Not Available: X</div>';
   }

require "dbconn2.php";

  $sql="SELECT service_id, service FROM service";
  $result=mysql_query($sql);
  $service_option="";
  
while ($row=mysql_fetch_array($result)) {

    $id=$row["service_id"];
    $service=$row["service"];
    $service_option.="<OPTION VALUE=\"$id\">".$service;
}
  $sql="SELECT con_id, first_name, last_name FROM consultant";
  $result=mysql_query($sql);
  $rconsultant_option="";

while ($row=mysql_fetch_array($result)) {

    $con_id1=$row["con_id"];
$con_id2=$row["con_id"];
    $con_id3=$row["con_id"];
    $first_name=$row["first_name"];
$last_name=$row["last_name"];
    $consultant_option1.="<OPTION VALUE=\"$con_id1\">".$first_name." ".$last_name;
$consultant_option2.="<OPTION VALUE=\"$con_id2\">".$first_name." ".$last_name;
    $consultant_option3.="<OPTION VALUE=\"$con_id3\">".$first_name." ".$last_name;
}

  $yeartoday = date(Y);
  $yearplus1 = date(Y)+1;
  
  for($y=$yeartoday;$y<=$yearplus1;$y++){  
       $selected = "";
       $longDate = date("Y", mktime(0,0,0,1,1,$y));
       if ($Year==$y){ 
       $selected = "selected \n";
        }
        $year_option.="<option value=\"$y\"$selected>$longDate</option>\n";
        }

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>SRC: Booking Form</title>
<link href="master.css" rel="stylesheet" type="text/css">
<link rel="shortcut icon" type="image/ico" href="favicon.ico">
<script type="text/javascript">
<!--

function OnSubmitForm()
{
  if(document.pressed == 'Check')
  {
   document.bookingForm.action ="checkavailability1.php";
  }
  else if(document.pressed == 'Book')
  {
    document.bookingForm.action ="book.php";
  }
  return true;
}

//-->
</script>
</head>

<body>

<div id="centerPanel"><div id="header">Booking Form</div><p>
<div id="content">
<form name="bookingForm" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" onSubmit="return OnSubmitForm();">

<label id="eventStart">Event Date:</label><br />
<select id="year3" name="year"><option value="<?php $_SESSION['values']['year']; ?>">Year <?=$year_option?></option></select> 

<?php
$arrMonth = array('01','02','03','04','05','06','07','08','09','10','11','12');
?>
<select id="month3" name="month">
   <option value="nil">Month</option>
   <?php
      foreach($arrMonth as $value)
      {
         echo '<option value="'.$value.'"'.($value==$_SESSION['values']['month'] ? ' selected="selected"' : '').'>'.$value.'</option>';
      }
   ?>

<?php
$arrDay = array('01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31');
?>
<select id="day3" name="day">
   <option value="nil">Day</option>
   <?php
      foreach($arrDay as $value)
      {
         echo '<option value="'.$value.'"'.($value==$_SESSION['values']['day'] ? ' selected="selected"' : '').'>'.$value.'</option>';
      }
   ?>
</select>

  <label id="service">Service:</label><br />
  <select id="serviceSelect" name="service">
   <option value="<?php $_SESSION['values']['service']; ?>">Service<?=$service_option?>
  </option>
  </select>
  </p>
  
  <p>
  <label id="unit">Unit:</label><br />
<?php
$arrUnit = array('Day','Hour');
?>
<select id="radioHour" name="unit">
   <option value="nil">Unit</option>
   <?php
      foreach($arrUnit as $value)
      {
         echo '<option value="'.$value.'"'.($value==$_SESSION['values']['unit']? ' selected="selected"' : '').'>'.$value.'</option>';
      }
   ?>
  
<label id="quantity">Quantity:</label>
<?php
$arrQuant = array('01','02','03','04','05','06','07');
?>
<select id="quantSelect" name="quantity">
   <option value="nil">[00]</option>
   <?php
      foreach($arrQuant as $value)
      {
         echo '<option value="'.$value.'"'.($value==$_SESSION['values']['quantity'] ? ' selected="selected"' : '').'>'.$value.'</option>';
      }
   ?>
</select>

<label id="eventStartTime">Start Time:</label><br/>
<?php
$arrStartTimeHr = array('09','10','11','12','13','14','15','16');
?>
<select id="hour" name="start_time_hr">
   <option value="nil">Hr</option>
   <?php
      foreach($arrStartTimeHr as $value)
      {
         echo '<option value="'.$value.'"'.($value==$_SESSION['values']['start_time_hr'] ? ' selected="selected"' : '').'>'.$value.'</option>';
      }
   ?>
</select>

<?php
$arrStartTimeMin = array('00','15','30','45');
?>
<select id="minute" name="start_time_min">
   <option value="nil">Min</option>
   <?php
      foreach($arrStartTimeMin as $value)
      {
         echo '<option value="'.$value.'"'.($value==$_SESSION['values']['start_time_min'] ? ' selected="selected"' : '').'>'.$value.'</option>';
      }
   ?>
</select>

<label id="extraInfo">Extra Information:</label><br />
<textarea id="extraInfoInput" name="extra_info" value="<?php $_SESSION['values']['extra_info']; ?>" onkeypress="return imposeMaxLength(this, 250);"></textarea>

<p>
<label id="con4">Consultant [1]:</label><br />
<select id="conSelect4" name="con_id1"><option value="<?php $_SESSION['values']['con_id1']; ?>">Select<?=$consultant_option1?></select>

<label id="con2">Consultant [2]:</label><br />
<select id="conSelect2" name="con_id2"><option value="<?php $_SESSION['values']['con_id2']; ?>">Select<?=$consultant_option2?></select>


<label id="con3">Consultant [3]:</label><br />
<select id="conSelect3" name="con_id3"><option value="<?php $_SESSION['values']['con_id3']; ?>">Select<?=$consultant_option3?></select>


<input  id= "check1" type ="submit" name="Check" onClick="document.pressed=this.value" value="Check"></p>
<p><input id="book" type ="submit" name="Book" onClick="document.pressed=this.value" value="Book"/></form>
</div>
</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.