当Form Form = POST

时间:2016-06-18 16:50:50

标签: php html post radio-button form-submit

我有一组单选按钮放在带有方法发布的表单中。但是只要表单发布,单选按钮的值就为零。以下是代码

	<form method="POST" action='insert_per.php'>
<table >
<caption>
     Grant Permissions
            </caption>
			<thead>
            <tr>
			    
                <th class="center"><strong>Name</strong></th>
                <th class="center"><strong>Email</strong></th>
				<?PHP if($_SESSION['user_group'] == 63){
				echo '<th class="center"><strong>System Admin</strong></th>';
                echo '<th class="center"><strong>Admin</strong></th>';
				echo '<th class="center"><strong>User</strong></th>';									
				} ?>
					<th class="center"><strong></strong></th>
              </tr>
			  </thead>
            <?php
            if($stmt->execute()){
                // output data of each row
                while($rows = $stmt->fetch(PDO::FETCH_ASSOC)){ ?>
                    <tr>
					    <td border="0" type="hidden"  style="display:none;"><input type="hidden" name="hidden" value=<?php echo $rows['member_id']; ?></td>   
                        <td class="center"><?php echo $rows['username']; ?></td>
						<td class="center"><?php echo $rows['email']; ?></td>
						
						<?PHP if($_SESSION['user_group'] == 63){ ?>
						      <td class="center"><input type='radio' id=<?php echo $rows['username']; ?> name="gp" value="system admin"
						      <?php echo ($rows['permission']== 31 )?'checked':'' ?>></input> </td>
						<td class="center"><input type='radio' id=<?php echo $rows['username']; ?> name="gp" value="admin"
						     <?php echo ($rows['permission']== 15 )?'checked':'' ?> ></input> </td>
							  <td class="center"><input type='radio' id=<?php echo $rows['username']; ?> name="gp" value="user"
						     <?php echo ($rows['permission']== 1 )?'checked':'' ?> ></input> </td> <?PHP }	?>								
												
                       	 <td class="center"><button name="SUBMIT" type="SUBMIT">submit</button></td>         
                           </tr>               
                    <?php
                }
            }
            ?> 
</table>
    </form> 

以下是insert_per.php的代码

echo "this is the gp  "+ $_POST['gp'];
echo "this is the gp  "+ $_POST['hidden'];

try{
 $stmt= $dbh->prepare("UPDATE `members_groups` SET `group_id`=(SELECT group_id FROM groups WHERE 
                                       group_name = ? ) WHERE member_id = ?"); 

$stmt->bindParam(1, $_POST['gp'] , PDO::PARAM_STR); 
$stmt->bindParam(2 , $_POST['hidden'] , PDO::PARAM_INT); 
   
if($stmt->execute()) {    
   echo "  the privilege was granted successfully ".'<BR>';
   echo "<a href='user_acc.php'>View result</a>";
}  
} catch(PDOException $e)
{
	echo "An error occured  ".$e->getMessage();
	
}    

单选按钮应生成以下值之一 “系统管理员”
“管理员”
“用户”
但它总是产生零“0”值。

0 个答案:

没有答案