html单选按钮没有POSTing

时间:2014-01-20 18:41:38

标签: php html forms

我正在使用带有单选按钮的表单向PHP发布值。但是,该值未发送。这是我的代码:

HTML:

<form action="voteupdate.php" id="form-id" method="post"onclick="document.getElementById(\'form-id\').submit();">  
  <input type="hidden" name="type" id="type" value="' . $type . '">  
  <input type="hidden" name="id" id="id" value="' . $id . '">  
  <div class="btn-group" data-toggle="buttons">  
    <label class="btn btn-default '.$vup.'">  
        <input type="radio" name="vote" id="1" value="1">  
     <span class="glyphicon glyphicon-chevron-up"></span> Vote up  
     </label>  
    <label class="btn btn-default '.$vd.'">  
        <input type="radio" name="vote" id="2" value="2">  
   <span class="glyphicon glyphicon-chevron-down"></span> Vote down  
    </label>  
</div>  
  </form>

PHP:

<?php session_start();   
include('config.php');  
  $type = $_POST['type'];  
  $id = $_POST['id'];  
  echo $_POST['vote'];  
    if ($type == "images"){  
  $tid = "imgid";  
  }  
    if ($type == "pages"){  
  $tid = "pageid";  
  }  
    if ($type == "posts"){  
  $tid = "postid";  
  }  
$table = str_replace(""," ",$type);  
$table = str_replace('"'," ",$table);  
$table = str_replace("'"," ",$table);  
$stmt= $pdo->prepare("SELECT * FROM '".$table."' WHERE ".$tid." = :imgid");  
$stmt->execute(array(':imgid' => $id));  
$stmt = $stmt->fetch();  

$vreg = explode(",", $stmt['votereg']);  
foreach ($vreg as $v) {  
$temp = explode("-", $v);  
if ($_SESSION['uid'] == $temp['0']){  
if (1 == $temp['1']){  
header( 'Location: votesys.php' ) ;  
}  
else  
{  
$instruction = "update-exists";  
}  
}  
    }  
    echo $instruction;  
?>

1 个答案:

答案 0 :(得分:2)

<form action="voteupdate.php" id="form-id" method="post"onclick="document.getElementById(\'form-id\').submit();">

缺少方法和onclick属性之间的空格:

<form action="voteupdate.php" id="form-id" method="post" onclick="document.getElementById(\'form-id\').submit();">