php页面按钮没有重定向,我尝试过使用ajax,但没有';我不明白它背后的全部意思

php页面按钮没有重定向,我尝试过使用ajax,但没有';我不明白它背后的全部意思,php,javascript,ajax,Php,Javascript,Ajax,下面是我的代码,有没有办法让按钮重定向到页面“vote.php”?是否有任何方法可以通过URL输入代码来传递所选列表值和复选框值 <?php require_once('Connections/was.php'); ?> <?php require_once('Connections/was.php'); ?> <head> <script> function checkLen(box) { var boxes=documen

下面是我的代码,有没有办法让按钮重定向到页面“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);

?>

函数复选框{
var-box=document.un['candcheckbox[]',len=box.length,i,count=0;
var crn=document.un.hiddenList3.value
对于(i=0;i crn){
box.checked=false;
}
}
}
函数生成器(选中的名称){
var kadaa=document.un.hiddenList.value;
var tayfeee=document.un.hiddenList2.value;
var wassimcheckbox=document.un['candcheckbox[]'];
var wassimcheckbox长度=wassimcheckbox.length;
var检查_name=“”;
对于(i==0;i
有没有办法让按钮重定向到页面“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);

?>
只要对PHP和表单稍加研究,这两个问题都很容易解决。这就是关于形式的全部概念。我知道W3Schools因其糟糕的建议而广受欢迎,但它们对表单的介绍简单、快速、简洁

您可以首先将按钮设置为一个
submit
和表单操作
vote.php

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



然后在
vote.php
中,确保使用
$\u GET[“nameOfElementInForm”]

检索变量。如果您提供的代码太多,请将问题具体化。到底是什么不起作用?包括您遇到的任何错误消息或描述。您应该将您在此处发布的代码减少到相关部分。我们喜欢帮助,但我们不会阅读10英里的代码。但是列表在change form.submit()上,因此如果我在表单中添加操作,它将在设置时重定向。。所以我需要的是一个java脚本重定向