?
Solved

posting two forms which are on two different pages

Posted on 2009-03-31
14
Medium Priority
?
189 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

0
Comment
Question by:mattibutt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 5
14 Comments
 
LVL 6

Expert Comment

by:SysTurn
ID: 24028935
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.
0
 
LVL 11

Author Comment

by:mattibutt
ID: 24028972
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
0
 
LVL 11

Expert Comment

by:spoxox
ID: 24028986
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.
0
Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

 
LVL 11

Author Comment

by:mattibutt
ID: 24029021
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
0
 
LVL 11

Author Comment

by:mattibutt
ID: 24029040
i dont want the checkbox to be on page one i only want it to on page two
0
 
LVL 11

Expert Comment

by:spoxox
ID: 24029369
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.
0
 
LVL 11

Author Comment

by:mattibutt
ID: 24029406
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'];
0
 
LVL 11

Expert Comment

by:spoxox
ID: 24029777
Are both forms on the same page?
0
 
LVL 11

Author Comment

by:mattibutt
ID: 24029797
no they are on different pages
0
 
LVL 11

Expert Comment

by:spoxox
ID: 24029888
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.
0
 
LVL 11

Author Comment

by:mattibutt
ID: 24029936
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

0
 
LVL 11

Author Comment

by:mattibutt
ID: 24029984
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
0
 
LVL 11

Accepted Solution

by:
spoxox earned 1500 total points
ID: 24031188
Are the forms going to the right pages? They both have Trivia.php. Is that page 2?

I don't know what to tell you. The solution to retrieving a value from a checkbox is shown above.
0
 
LVL 11

Author Closing Comment

by:mattibutt
ID: 31564792
thanks for your help but  i have sorted this problem differently
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question