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

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...
LVL 12
jazzIIIloveAsked:
Who is Participating?
 
jazzIIIloveAuthor Commented:
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
 
gamebitsCommented:
<input type="checkbox" name="chk1" value="passit">

next page

$chk = $_POST['chk1'];

echo "$chk";  //will display passit
0
 
Michael701Commented:
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
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
jazzIIIloveAuthor Commented:
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
 
Michael701Commented:
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
 
jazzIIIloveAuthor Commented:
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
 
jazzIIIloveAuthor Commented:
>>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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.