We help IT Professionals succeed at work.

posting two forms which are on two different pages

mattibutt
mattibutt asked
on
217 Views
Last Modified: 2013-12-12
hi
i am posting two forms from two different pages but its not producing the desire results.
what i am trying to do is basically once user enter the code correctly they see the next screen where they must agree to terms and conditions currently i am able to post the checkbox value from the page one but i want to do this on the page but its not working i need help to retrieve the checkbox value from page 2 instead of page 1
on the first screen i enter the code below codes are for the first page
<table width="500">
      <tr >
            <td align="center" bgcolor="d3d3d3"><strong>Set Me Up ! </strong></td>
      </tr>
      <?php
      if(isset($error))
      {
      ?>
      <tr  >
            <td align="center" bgcolor="ff0000"><?php echo $error; $error = ""; ?></td>
      </tr>
      <?php
      }
      ?>
      <tr>
            <td align="center"  style="border:#000033; border-width:1px">
            <form action="Trivia.php?menu=set" method="post">
            <table width="80%">
            <tr>
            <td width="30%" style="text-align:right">Enter Code To Play . &raquo;</td>
            <td width="70%"><input type="text" name="name_full" style="width:150" /></td>
            </tr>
            <tr>
            <td width="30%" style="text-align:right"> </td>
            <td width="70%"><input type="hidden" name="email_id" style="width:150" /></td>
            </tr>
                  <tr>
            <td width="30%" style="text-align:right"> </td>
            <td width="70%"><input type="checkbox" name="term" value= "1" style="width:50" />
            </td>
            </tr>
            
            
            <tr>
            <td width="30%" style="text-align:right"> </td>
            <td width="70%"><input type="hidden" name="total_question" value= "10" style="width:50" /></td>
            </tr>
            <tr>
            <td width="30%" style="text-align:right"> </td>
            <td width="70%"><input type="hidden" name="time" value= "1" style="width:50" />
            </td>
            </tr>
            <tr><td></td><td><input type="image" src="images/start.jpg" />
            <input type="hidden" name="next_step" value="true" />
            </td></tr>
            </table></form>
            </td>
      </tr >
      
      </table>
2nd page
if user enter correct code it takes them to the 2nd page code below are for the 2nd page
<form action="Trivia.php?menu=start" method="post">

            
            <tr>
            <td width="30%" style="text-align:right"> </td>
            <td width="70%"><input type="hidden" name="total_question" value= "10" style="width:50" /></td>
            </tr>
            <tr>
            <td width="30%" style="text-align:right"> </td>
            <td width="70%"><input type="hidden" name="time" value= "1" style="width:50" />
            </td>
            </tr>
            <tr>
            <td width="30%" style="text-align:right"> </td>
            <td width="70%"><input type="checkbox" name="term" value= "1" style="width:50" />
            </td>
            </tr>
            
            <input type="hidden" name="full_name" id="full_name" value="<?php echo $_SESSION['full_name'];  ?>"  /></td>
                        
            <tr><td></td><td><input type="image" src="images/start.jpg" />
            <input type="hidden" name="next_step" value="true" />
            </td></tr>
      
            </table>
        </form>
            </td>
      </tr >
</tr>

global $quiz_ready;
$quiz_ready = 'no';
if($_GET['menu']== 'set' && $quiz_ready=='no')
 
{
global $error,$total_question,$time_sec,$time_min,$cat1,$use_tedu,$total_rows,$correct,$wrong,$unanswered;
 
$query = "SELECT * FROM enter WHERE randomcode='{$_POST['name_full']}'  ";
$res = mysql_query($query);
$query = "SELECT * FROM enterused WHERE randomcode='{$_POST['name_full']}'  ";
$ress = mysql_query($query);
 
 
if (mysql_num_rows($res)){
  $access_granted = true;
} else {
 $access_granted = false;
 $quiz_ready = 'no';
 ($_GET['menu']== 'setup');
}
 
if (mysql_num_rows($ress)){
  $access_granted = false;
 $quiz_ready = 'no';
 ($_GET['menu']== 'setup');
}
if ($access_granted){
 if(isset($_POST['next_step']) && isset($_POST['total_question']) && isset($_POST['time'])  )
 {
       // Get random questions
      $stamp = date('mdyHis');
      $_SESSION['quiz_date'] = date('d-M-y ,D');
      $_SESSION['quiz_time'] = date('H:i:s');
      $_SESSION['quiz_id'] = $stamp;
      $_SESSION['full_name'] = $_POST['name_full'];
      $_SESSION['quiz_term'] = $_POST['term'];
      $_SESSION['quiz_total_question'] = $_POST['total_question'];
      $_SESSION['quiz_time_sec'] = $_POST['time'] * 6000 ;  // time in seconds
	  $_SESSION['quiz_time_msec'] = $_POST['time'] * 60 * 1000;
      $_SESSION['quiz_time_min'] = $_POST['time'];
      $_SESSION['quiz_cat1'] = $_POST['cat1'];
      
	
      $query = "SELECT * FROM pq_crtp_quiz";
      $sql = mysql_query($query);
      $total_rows = mysql_num_rows($sql);
      $i=0;
      array($rand_arr);
      while($i < $_SESSION['quiz_total_question'])
      {
      $rand_num = rand(1,$total_rows - 1);
      if(!@array_search($rand_num,$rand_arr))
      {
      
      $rand_arr[$i] = $rand_num;
      $i++;
      }
      }
      global $quiz_data;
      for($i=0;$i < $_SESSION['quiz_total_question'];$i++)
      {
      $query = "SELECT * FROM pq_crtp_quiz WHERE id = ".$rand_arr[$i];
      $sql = mysql_query($query);
      $quiz_data[$i] = mysql_fetch_array($sql);
      
      }
      $_SESSION['quiz_data']=$quiz_data;
      //print_r($quiz_data);
 }
 elseif(isset($_POST['next_step']))
 {
       $error = "Some of the fields are left empty !";
      header('Location: Trivia.php?menu=setup');
 }
} else {
 
 
header('Location: Trivia.php?menu=setup&code_error=1');
echo "incorrect code";
 exit();
}
}

Open in new window

Comment
Watch Question

Commented:
Hi,

Before using $_SESSION , you need to start it first by using session_start();

Also note that checkbox value will not be posted to your php code if it's not checked.

Author

Commented:
i am using session start everything else is posted except checkbox value problem is i am trying to break down the quiz before as soon user entered code it displayed quiz now i want to add terms and condition page

Commented:
I'm not sure exactly what you are trying to do, but:

The VALUE attribute for the checkbox might not be what you're looking for. Instead, you might want CHECKED or UNCHECKED.
<input type="checkbox" name="term" CHECKED style="width:50" />
When testing on page two, you can check the box on page 2 to match page 1 like this:
<input type="checkbox" name="term"
<?php echo $_POST['term']=="on"?"CHECKED":"UNCHECKED";?>
style="width:50" />

In any case, when testing whether a checkbox is checked, this works.
if ($_POST['term']=="on")
...

Hope this helps.

Author

Commented:
hi
thing is i had one stage before starting the quiz as soon  code is entered the quiz screen is shown now i am trying to insert another page before displaying the quiz i have gone through with it problem is i cant post anything from the 2nd page i just realised this

Author

Commented:
i dont want the checkbox to be on page one i only want it to on page two

Commented:
I don't know why you wouldn't be able to post from page 2. Sounds like a small problem (once it's found!). Can you clarify?

To remove the checkbox from Page 1, just delete it by removing these lines:

                  <tr>
            <td width="30%" style="text-align:right"> </td>
            <td width="70%"><input type="checkbox" name="term" value= "1" style="width:50" />
            </td>
            </tr>

If you want to remember whether the box was checked without displaying the box, you can make it a hidden field:

  <input type="hidden" name="hiddenCBval" id="hiddenCBval" value="<?php echo ... ?>" />

where ... is the data you want to remember.

Author

Commented:
hi spoxo
this small problem is becoming a hectic i think there are two things i should mention
number 1
the both pages page1 and page 2 form name is exactly same
all the other values are posted and kept in the session like the current issue i am working on is   $_SESSION['quiz_term'] = $_POST['term'];
 if(isset($_POST['next_step']) && isset($_POST['total_question']) && isset($_POST['time'])  )
 {
       // Get random questions
      $stamp = date('mdyHis');
      $_SESSION['quiz_date'] = date('d-M-y ,D');
      $_SESSION['quiz_time'] = date('H:i:s');
      $_SESSION['quiz_id'] = $stamp;
      $_SESSION['full_name'] = $_POST['name_full'];
      $_SESSION['quiz_term'] = $_POST['term'];
      $_SESSION['quiz_total_question'] = $_POST['total_question'];
      $_SESSION['quiz_time_sec'] = $_POST['time'] * 6000 ;  // time in seconds
        $_SESSION['quiz_time_msec'] = $_POST['time'] * 60 * 1000;
      $_SESSION['quiz_time_min'] = $_POST['time'];
      $_SESSION['quiz_cat1'] = $_POST['cat1'];

Commented:
Are both forms on the same page?

Author

Commented:
no they are on different pages

Commented:
Recap (please verify):
Page 1 form: Enter code_____

Page 2 form: Agree to terms checkbox [ ]


Why is the checkbox on page 1?


Please supply more info describing:
1) what you want to happen
2) what is happening
perhaps source as well.

Author

Commented:
hi
i have been looking into the code and see what might be possibly wrong these are the server side code
once it gets to menu = set then it checks for code but after that i think it doesnt do anything which comes  from the page two where i am putting the checkbox the following server side codes are prior to creating page two where i changed the menu == start to set
global $quiz_ready;
$quiz_ready = 'no';
if($_GET['menu']== 'start' && $quiz_ready=='no')

{
global $error,$total_question,$time_sec,$time_min,$cat1,$use_tedu,$total_rows,$correct,$wrong,$unanswered;

$query = "SELECT * FROM enter WHERE randomcode='{$_POST['name_full']}'  ";
$res = mysql_query($query);
$query = "SELECT * FROM enterused WHERE randomcode='{$_POST['name_full']}'  ";
$ress = mysql_query($query);


if (mysql_num_rows($res)){
  $access_granted = true;
} else {
 $access_granted = false;
 $quiz_ready = 'no';
 ($_GET['menu']== 'setup');
}

if (mysql_num_rows($ress)){
  $access_granted = false;
 $quiz_ready = 'no';
 ($_GET['menu']== 'setup');
}



if ($access_granted){
 if(isset($_POST['next_step']) && isset($_POST['total_question']) && isset($_POST['time']) )
 {
       // Get random questions
      $stamp = date('mdyHis');
      $_SESSION['quiz_date'] = date('d-M-y ,D');
      $_SESSION['quiz_time'] = date('H:i:s');
      $_SESSION['quiz_id'] = $stamp;
      $_SESSION['full_name'] = $_POST['name_full'];
     
      $_SESSION['email'] = $_POST['email_id'];
      $_SESSION['quiz_total_question'] = $_POST['total_question'];
      $_SESSION['quiz_time_sec'] = $_POST['time'] * 6000 ;  // time in seconds
        $_SESSION['quiz_time_msec'] = $_POST['time'] * 60 * 1000;
      $_SESSION['quiz_time_min'] = $_POST['time'];
      $_SESSION['quiz_cat1'] = $_POST['cat1'];
     

      $query = "SELECT * FROM pq_crtp_quiz";
      $sql = mysql_query($query);
      $total_rows = mysql_num_rows($sql);
      $i=0;
      array($rand_arr);
      while($i < $_SESSION['quiz_total_question'])
      {
      $rand_num = rand(1,$total_rows - 1);
      if(!@array_search($rand_num,$rand_arr))
      {
     
      $rand_arr[$i] = $rand_num;
      $i++;
      }
      }
      global $quiz_data;
      for($i=0;$i < $_SESSION['quiz_total_question'];$i++)
      {
      $query = "SELECT * FROM pq_crtp_quiz WHERE id = ".$rand_arr[$i];
      $sql = mysql_query($query);
      $quiz_data[$i] = mysql_fetch_array($sql);
     
      }
      $_SESSION['quiz_data']=$quiz_data;
      //print_r($quiz_data);
 }
 elseif(isset($_POST['next_step']))
 {
       $error = "Some of the fields are left empty !";
      header('Location: Trivia.php?menu=setup');
 }
} else {

 
header('Location: Trivia.php?menu=setup&code_error=1');
echo "incorrect code";
 exit();

global $quiz_ready;
$quiz_ready = 'no';
if($_GET['menu']== 'set' && $quiz_ready=='no')
 
{
global $error,$total_question,$time_sec,$time_min,$cat1,$use_tedu,$total_rows,$correct,$wrong,$unanswered;
 
$query = "SELECT * FROM enter WHERE randomcode='{$_POST['name_full']}'  ";
$res = mysql_query($query);
$query = "SELECT * FROM enterused WHERE randomcode='{$_POST['name_full']}'  ";
$ress = mysql_query($query);
 
 
if (mysql_num_rows($res)){
  $access_granted = true;
} else {
 $access_granted = false;
 $quiz_ready = 'no';
 ($_GET['menu']== 'setup');
}
 
if (mysql_num_rows($ress)){
  $access_granted = false;
 $quiz_ready = 'no';
 ($_GET['menu']== 'setup');
}
$term;
$term = 1;
 
 
 
 
if ($access_granted){
	
 if(isset($_POST['next_step']) && isset($_POST['total_question']) && isset($_POST['time'])  )
 {
       // Get random questions
      $stamp = date('mdyHis');
      $_SESSION['quiz_date'] = date('d-M-y ,D');
      $_SESSION['quiz_time'] = date('H:i:s');
      $_SESSION['quiz_id'] = $stamp;
      $_SESSION['full_name'] = $_POST['name_full'];
      $_SESSION['quiz_term'] = $_POST['term'];
      $_SESSION['quiz_total_question'] = $_POST['total_question'];
      $_SESSION['quiz_time_sec'] = $_POST['time'] * 6000 ;  // time in seconds
	  $_SESSION['quiz_time_msec'] = $_POST['time'] * 60 * 1000;
      $_SESSION['quiz_time_min'] = $_POST['time'];
      $_SESSION['quiz_cat1'] = $_POST['cat1'];
      
	
      $query = "SELECT * FROM pq_crtp_quiz";
      $sql = mysql_query($query);
      $total_rows = mysql_num_rows($sql);
      $i=0;
      array($rand_arr);
      while($i < $_SESSION['quiz_total_question'])
      {
      $rand_num = rand(1,$total_rows - 1);
      if(!@array_search($rand_num,$rand_arr))
      {
      
      $rand_arr[$i] = $rand_num;
      $i++;
      }
      }
      global $quiz_data;
      for($i=0;$i < $_SESSION['quiz_total_question'];$i++)
      {
      $query = "SELECT * FROM pq_crtp_quiz WHERE id = ".$rand_arr[$i];
      $sql = mysql_query($query);
      $quiz_data[$i] = mysql_fetch_array($sql);
      
      }
      $_SESSION['quiz_data']=$quiz_data;
      //print_r($quiz_data);
 }
 elseif(isset($_POST['next_step']))
 {
       $error = "Some of the fields are left empty !";
      header('Location: Trivia.php?menu=setup');
 }
} else {
 
 
header('Location: Trivia.php?menu=setup&code_error=1');
echo "incorrect code";
 exit();
}

Open in new window

Author

Commented:
hi
i have put the checkbox on page 1 to test whether it post from there it is not going to be there its only going to be on page two.
when user enter the correct code page two should display T&C where he will agree to terms and condition and then the quiz will be displayed
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
thanks for your help but  i have sorted this problem differently
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.