0

以下是我的代码,有没有办法让按钮重定向到页面“vote.php”?有没有办法通过 URL 传递选定的列表值和复选框值?

<?php require_once('Connections/was.php'); ?>
<?php require_once('Connections/was.php'); ?>
<head>


<script>
  function checkLen(box) { 

     var boxes=document.un['candcheckbox[]'],len=boxes.length,i,count=0;
     var crn=document.un.hiddenList3.value

   for(i=0;i<len;i++) {

        count+=(boxes[i].checked) ? 1 : 0;
        if(count> crn)      {
           box.checked=false;
                            }

               }

  }
  </script>


  <script>
function generateURL(checked_names) {
    var kadaa = document.un.hiddenList.value;
    var tayfeeee = document.un.hiddenList2.value;


  var wassimcheckboxes = document.un['candcheckbox[]'];
  var wassimcheckboxesLENGTH= wassimcheckboxes.length;
    var checked_names = "";
    for ( i == 0;  i < wassimcheckboxesLENGTH; i++) {
    if (wassimcheckboxes[i].checked) {
        checked_names[i].value = wassimcheckboxes[i].value;
    }
    }


window.location.href="vote.php?names="+checked_names+"&tayfe="+tayfeeee+"&cada2="+kadaa

}

</script>




</head>
<body>



<?php require_once('Connections/was.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "",          $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ?                                     mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
  $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  break;    
case "long":
case "int":
  $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  break;
case "double":
  $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  break;
case "date":
  $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  break;
case "defined":
  $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  break;
  }
  return $theValue;
}
}

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
case "text":
  $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  break;    
case "long":
case "int":
  $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  break;
case "double":
  $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  break;
case "date":
  $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  break;
case "defined":
  $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  break;
  }
  return $theValue;
}
}

mysql_select_db($database_was, $was);
$query_CasaList = "SELECT CASA_ID FROM casa";
$CasaList = mysql_query($query_CasaList, $was) or die(mysql_error());
$row_CasaList = mysql_fetch_assoc($CasaList);
$totalRows_CasaList = mysql_num_rows($CasaList);

if(isset($_GET['casaList'])){
$sqlvar=$_GET['casaList'];

}else{
    $sqlvar='-1';
    }

if(isset($_GET['ReliGList'])){
$sqlvar2=$_GET['ReliGList'];

}else{
    $sqlvar2='-1';
    }








mysql_select_db($database_was, $was);
$query_RELIG1 = "SELECT RELIGION_SECT FROM circonscriptionreligionnumber WHERE                 CIRCONCRIPTION_ID = (Select CIRCONCRIPTION_ID FROM casa WHERE CASA_ID ='".$sqlvar."')";
$RELIG1 = mysql_query($query_RELIG1, $was) or die(mysql_error());
$row_RELIG1 = mysql_fetch_assoc($RELIG1);
$totalRows_RELIG1 = mysql_num_rows($RELIG1);

mysql_select_db($database_was, $was);
$query_wasCandNameC = "SELECT CAND_NAME FROM candidates WHERE CIRCONCRIPTION_ID = (Select CIRCONCRIPTION_ID FROM casa WHERE CASA_ID ='".$sqlvar."') AND RELIGION_SECT ='".$sqlvar2."'";
$wasCandNameC = mysql_query($query_wasCandNameC, $was) or die(mysql_error());
$row_wasCandNameC = mysql_fetch_assoc($wasCandNameC);
$totalRows_wasCandNameC = mysql_num_rows($wasCandNameC);

mysql_select_db($database_was, $was);
$query_crnNumber = "select CRNNUMBER from circonscriptionreligionnumber where             CIRCONCRIPTION_ID =(select CIRCONCRIPTION_ID from casa where CASA_ID= '".$sqlvar."') and RELIGION_SECT ='".$sqlvar2."'";
$crnNumber = mysql_query($query_crnNumber, $was) or die(mysql_error());
$row_crnNumber = mysql_fetch_array($crnNumber);
$totalRows_crnNumber = mysql_num_rows($crnNumber);









?>


<form name="un" method="GET" action="" >
  <p>


    <label for="casaList">Choose your Casa</label>
<select name="casaList" id="casaList" title="Casa" onChange="un.submit()">
  <option value=""></option>

  <?php
do {  
?>
  <option value="<?php echo $row_CasaList['CASA_ID']?>" <?php         if(isset($_GET['casaList'])){if ($_GET['casaList']==$row_CasaList['CASA_ID']){echo "selected";}}?>><?php echo $row_CasaList['CASA_ID']?></option>
      <?php
} while ($row_CasaList = mysql_fetch_assoc($CasaList));
  $rows = mysql_num_rows($CasaList);
  if($rows > 0) {
  mysql_data_seek($CasaList, 0);
  $row_CasaList = mysql_fetch_assoc($CasaList);
  }
?>


    </select>


<label for="ReliGList">Select Candidate's Religious Views</label>


<select name="ReliGList" id="ReliGList" title="religion" onChange="un.submit()" >
  <option value=""></option>

  <?php
do {  
?> 

  <option value="<?php echo $row_RELIG1['RELIGION_SECT']?>" <?php 
if(isset($_GET['ReliGList'])){if 
($_GET['ReliGList']==$row_RELIG1['RELIGION_SECT']){echo "selected";}}




?>  >
  <?php echo $row_RELIG1['RELIGION_SECT']?></option>


  <?php
} while ($row_RELIG1 = mysql_fetch_assoc($RELIG1));
  $rows = mysql_num_rows($RELIG1);
  if($rows > 0) {
  mysql_data_seek($RELIG1, 0);
  $row_RELIG1 = mysql_fetch_assoc($RELIG1);
  }
?>

</select>




<table width="275" border="1">
  <tr>
<th width="115" scope="col">Check Area</th>
<th width="130" scope="col">Candidate Name</th>
  </tr>
    <?php
do {  
?>


  <tr>
<td><input type="checkbox" name="candcheckbox[]" id = "candcheckbox[]" value="<?php     echo $row_wasCandNameC['CAND_NAME']; ?>" onChange="checkLen(this);"/></td>
<td><?php echo $row_wasCandNameC['CAND_NAME']; ?></td>
  </tr>






  <?php
} while ($row_wasCandNameC = mysql_fetch_assoc($wasCandNameC));
  $rows = mysql_num_rows($wasCandNameC);
  if($rows > 0) {
  mysql_data_seek($wasCandNameC, 0);
  $row_wasCandNameC = mysql_fetch_assoc($wasCandNameC);
  }
?>

 <input type="hidden"  name="hiddenList" value="<?php echo $sqlvar; ?>" ></input>
 <input type="hidden"  name="hiddenList2" value="<?php echo $sqlvar2; ?>" ></input>

       <?php
do {  
?> 
 <input type="hidden"  name='hiddenList3' value="<?php echo         $row_crnNumber['CRNNUMBER']; ?>" ></input>


 <?php
} while ($row_crnNumber = mysql_fetch_assoc($crnNumber));
  $rows = mysql_num_rows($crnNumber);
  if($rows > 0) {
  mysql_data_seek($crnNumber, 0);
  $row_crnNumber = mysql_fetch_assoc($crnNumber);
  }
?>


 </table>   






 <br>


<input type="button" name="vote" value="vote" onclick="generateURL(this);"/>





  </form>  



</body>




<?php
mysql_free_result($CasaList);
mysql_free_result($RELIG1);

mysql_free_result($wasCandNameC);

mysql_free_result($crnNumber);

?>
4

1 回答 1

0

您问

有没有办法让按钮重定向到页面“vote.php”?有没有办法通过 URL 传递选定的列表值和复选框值?

通过对 PHP 和表单的一些研究,这两个问题都很容易解决。这是关于形式的全部概念。我知道 W3Schools 因为糟糕的建议而广受欢迎,但他们对表格的介绍简单、快速、简洁。http://www.w3schools.com/php/php_forms.asp

你可以先让你的按钮 asubmit和你的表单动作vote.php

<form name="un" method="GET" action="vote.php">

<input type="submit" value="vote"/>

然后vote.php确保你检索变量$_GET["nameOfElementInForm"]

于 2012-10-06T19:29:29.547 回答