3 Replies - 3215 Views - Last Post: 26 July 2011 - 01:00 AM Rate Topic: -----

#1 kimkim92  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 06-July 11

How send session variable across multiple pages?HELP unsolved for 3day

Posted 25 July 2011 - 09:43 PM

Hi guys i really need help i have been trying to send the session variable across multiple page to insert to database but it seem like not working.

Page 1

<?php session_start();
$_SESSION['course'] = $_POST['course'];
$_SESSION['course']= $course;

?>
<script type="text/javascript">
<!--

function validate_form ( )
{
    valid = true;

    if ( document.course.course.selectedIndex == 0 )
    {
        alert ( "Please select a course." );
        valid = false;
    }

    return valid;
}

//-->
</script>



<html>
    <head>
        <title>Register</title>
    </head>
    <body leftmargin="0" topmargin="0">

        <form action="Date.php" name="course" method="post" onsubmit="return validate_form()">
            <table align="center" width = "300%">
                <tr>
                    <td align = "center">

                        <h2>SJAS -Select Course</h2>
                        <h4>Please Choose the Course you wish to enroll in .</h4>
                        <h2>Course Selection</h2>
                        <hr>
                    </td>
                </tr>
                <tr>
            </table>
            
                
                    <table align = "center">
<tr>

                               <td>
                                <select name="course" value="course"  id="course">
                                    <option value="value1"selected="selected" >--Select Course--</option>

                                    <option value="Basic Cardiac Life Support">Basic Cardiac Life Support</option>
                                    <option value="CPR">CPR</option>
                                    <option value="Basic First Aid">Basic First Aid</option>
                                     <option value="Adult First Aid">Adult First Aid</option>
                                      <option value="Home and Nursing">Home and Nursing</option>
                                </select>
                            </td>


                         </tr>
            </table>
            <br>
             <center> <input name="submit" type="submit" value="Next" /></center>
             </form>
        </body>
        </html>
       


Page 5
<?php session_start();


 if(isset($_POST)){
     
     $no=$_POST['no'];
     echo $_POST['course'];
     $_SESSION['course'] = $_POST['course'];





$link = mysqli_connect('localhost', 'root', '', 'sjas')or die(mysqli_connect_error());

             for($count=1;$count<=$no;$count++)
             {
                 $fullname=$_POST['fullname'.$count];
                         $nric=$_POST['nric'.$count];
                          $age=$_POST['age'.$count];
                           $gender=$_POST['gender'.$count];
                            $email=$_POST['email'.$count];
                             $position=$_POST['position'.$count];
                              $sdf=$_POST['sdf'.$count];
                                 $course= $_POST['course'.$count];

                                  $count= $count++;
                                  

                              
 $query = "INSERT INTO employee(fullname,nric,age,gender,email,position,sdf,course) VALUES ('$fullname','$nric','$age','$gender','$email','$position','$sdf','.$course.')";
 $status = mysqli_query($link,$query) or die(mysqli_error($link));
             }}

	mysqli_close($link);


?>





    <head>
        <title>Register</title>
    </head>
    <body leftmargin="0" topmargin="0">

        <form action="email.php" method="post" >
            <table align="center" width = "300%">
                <tr>
                    <td align = "center">

                        <h2>SJAS -Confirm</h2>
                        <h4>Please confirm that you wish to continue .</h4>
                        <?php
  	echo $message;
  ?>

                        <hr>
                    </td>
                </tr>

            </table>


            <br>
            <table align="center">
                <tr>
            <td><input name="submit" type="submit" value="Confirm" /></td>
            <td>  <input type=button onclick="location.href='home.php'" value='Cancel'> </td>

            </tr>
            </table>
        </form>
        </html>



Is This A Good Question/Topic? 0
  • +

Replies To: How send session variable across multiple pages?HELP unsolved for 3day

#2 AdaHacker  Icon User is offline

  • Resident Curmudgeon

Reputation: 452
  • View blog
  • Posts: 811
  • Joined: 17-June 08

Re: How send session variable across multiple pages?HELP unsolved for 3day

Posted 25 July 2011 - 10:05 PM

This block of code makes no sense:
$_SESSION['course'] = $_POST['course'];
$_SESSION['course']= $course;

You set the session variable to a POST variable (which will only work if this page is the POST target, which it doesn't look like) and then you immediately overwrite that with $course, which is not set. So even if you get the session variable set in at the top of the first page, you immediately wipe it out.
Was This Post Helpful? 2
  • +
  • -

#3 kimkim92  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 06-July 11

Re: How send session variable across multiple pages?HELP unsolved for 3day

Posted 25 July 2011 - 10:08 PM

View PostAdaHacker, on 25 July 2011 - 10:05 PM, said:

This block of code makes no sense:
$_SESSION['course'] = $_POST['course'];
$_SESSION['course']= $course;

You set the session variable to a POST variable (which will only work if this page is the POST target, which it doesn't look like) and then you immediately overwrite that with $course, which is not set. So even if you get the session variable set in at the top of the first page, you immediately wipe it out.


oh stupid me.then how can i set the variable first to hold/store the form?
Was This Post Helpful? 0
  • +
  • -

#4 E_Geek  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 45
  • View blog
  • Posts: 236
  • Joined: 20-February 11

Re: How send session variable across multiple pages?HELP unsolved for 3day

Posted 26 July 2011 - 01:00 AM

Session variables are set using the session associative array.

$_SESSION['var'] = 'value';



If the value is to be a variable, the variable must be set prior to it being stored, or you will receive a warning.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1