[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

how can i pass a checkbox value from one php page to another php page?

Posted on 2009-04-26
7
Medium Priority
?
465 Views
Last Modified: 2012-05-06
Hi there;

how can i pass a checkbox value from one php page to another php page?

Any sample code you can provide?

Best regards...
0
Comment
Question by:jazzIIIlove
  • 4
  • 2
7 Comments
 
LVL 28

Expert Comment

by:gamebits
ID: 24236758
<input type="checkbox" name="chk1" value="passit">

next page

$chk = $_POST['chk1'];

echo "$chk";  //will display passit
0
 
LVL 19

Expert Comment

by:Michael701
ID: 24236808
If the checkbox is NOT checked then it may not set the post variable. Depending on your error reporting this may not be a problem.

$chk=""
if (isset($_POST['chk1'])
  $chk=$_POST['chk1'];
0
 
LVL 12

Author Comment

by:jazzIIIlove
ID: 24237753
Hi there;

ok...I tried but no use...the thing is there is a php page having checkbox, after clicking submit button, the checking process is evaluated successfully and in a right manner and the result is displayed again in the same page...But my problem starts from here, there is a button below the new page, and it generates excel file...It generates the excel files for text fields successfully but for the checkbox condition it couldn't...I couldn't figure out...

Best regards...
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 19

Expert Comment

by:Michael701
ID: 24237783
Sounds like you either have to save the checkbox value in a hidden field or one page 2 display a checkbox with the previous state checked=CHECKED
0
 
LVL 12

Author Comment

by:jazzIIIlove
ID: 24237813
To be more precise:

find.php
<p>&nbsp;Never Login: <input type="checkbox" name="neverLogin" id="neverLogin" value="yes" <?php if($neverLogin=='yes') echo "checked" ; ?>></p>
<p>&nbsp;Never Update: <input type="checkbox" name="neverUpdate" id="neverUpdate" value="yes" <?php if($neverUpdate=='yes') echo "checked" ; ?>></p>
....
A MySQL process:

$search_neverLogin = mysql_real_escape_string($_POST['neverLogin']);
$search_neverUpdate = mysql_real_escape_string($_POST['neverUpdate']);

$str=  "SELECT * FROM `".getConfigVal("sqlTablePrefix",2)."_users` WHERE 1=1";                                                                  
                                    
                                     $where = true;
                                    
if($search_neverLogin!="")
{
$str .= " AND (`lastLogin` IS NULL )";
}
                                    
if($search_neverUpdate!="")
{
$str .= " AND (`lastLogin` IS NOT NULL ) AND (`alumniSex` = '' )";
}

query executed successfully and in right manner in the same page...

if($_SESSION['userType']=="admin"){
echo "<p><a href='/alumni/pages/newFile.page.inc.php?".$searchstr."'>Generate XLS file</a></p>";
}

newFile.page.inc.php:
sadly same queries with find.php, they are working perfectly except for never login and never update which are checkboxes in the previous page...I couldn't pass the variables...I don't understand why...

  $result = dbQuery( $str);
                              
                                          $header = "User Name" . "\t". "First Name" . "\t" ."Maiden Name" . "\t" .  "alumniLastName" . "\t" . "alumniYear" . "\t" . "alumniSex" . "\t" . "alumniBloodType" ."\t" . "alumniDateOfBirth" . "\t" . "alumniEmail" ."\t".
                                          "\t" . "alumniMilitaryStatus" . "\t" . "alumniPhone" . "\t" . "alumniGSM" . "\t" . "alumniAddress" . "\t" . "alumniCity" . "\t" . "alumniCountry" . "\t" . "alumniKurum" . "\t" . "alumniUnvan" ."\t" . "alumniSektor" ."\t" . "alumniGradMaster" ."\t" . "alumniGradDoctorate" . "\t" . "alumniGradMasterYear" . "\t" . "alumniGradMasterDepartment" . "\t" . "alumniGradMasterUniversity" ."\t" . "alumniGradDoctorateYear" . "\t" . "alumniGradDoctorateDepartment" . "\t" . "alumniGradDoctorateUniversity" . "\t" . "alumniAS".  "\t" . "alumniNeverLogin"."\t" . "alumniNeverUpdate". "\t". "\n";                                          
                                    while ($row = mysql_fetch_assoc($result)) {                                          
                                          $data .= $row['alumniUserName'] . "\t" . $row['alumniFirstName'] . "\t" . $row['alumniMaidenName'] . "\t" . $row['alumniLastName'] . "\t" . $row['alumniYear'] . "\t" . $row['alumniSex']. "\t" . $row['alumniBloodType']."\t" . $row['alumniDateOfBirth'] . "\t" . $row['alumniEmail'] ."\t".
                                          "\t" . $row['alumniMilitaryStatus'] . "\t" . $row['alumniPhone'] . "\t" . $row['alumniGSM'] . "\t" . $row['alumniAddress'] . "\t" . $row['alumniCity'] . "\t" . $row['alumniCountry'] . "\t" . $row['alumniKurum'] . "\t" . $row['alumniUnvan'] ."\t" . $row['alumniSektor'] ."\t" . $row['alumniGradMaster'] ."\t" . $row['alumniGradDoctorate'] . "\t" . $row['alumniGradMasterYear'] . "\t" . $row['alumniGradMasterDepartment'] . "\t" . $row['alumniGradMasterUniversity'] ."\t" . $row['alumniGradDoctorateYear'] . "\t" . $row['alumniGradDoctorateDepartment'] . "\t" . $row['alumniGradDoctorateUniversity'] . "\t" . $row['alumniAS']. "\t" .  $_REQUEST['search_neverLogin']. "\t" .$_REQUEST['search_neverUpdate']. "\t" ."\n";
                                    }
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=searchresults.xls");
header("Pragma: no-cache");
header("Expires: 0");
echo $header."\n".$data;
0
 
LVL 12

Accepted Solution

by:
jazzIIIlove earned 0 total points
ID: 24237834
So, my code seems little complicated i must admit...How can i pass more than 1 php variable to other page:

I mean I would like to pass the values of checkboxes...

How to modify below code? Is it possible?

if($_SESSION['userType']=="admin"){
echo "<p><a href='/alumni/pages/newFile.page.inc.php?".$searchstr."'>Generate XLS file</a></p>";
}

0
 
LVL 12

Author Comment

by:jazzIIIlove
ID: 24238019
>>Sounds like you either have to save the checkbox value in a hidden field or one page 2 display a >>checkbox with the previous state checked=CHECKED

my checkboxes are not in a hidden field, i am losing the state in the new page...If only i can save the states...

Best regards...and thanks for your patience
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses
Course of the Month20 days, 11 hours left to enroll

865 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