单选按钮POST问题

时间:2014-03-31 01:10:00

标签: php mysql sql radio-button

所以这就是问题所在。我正在运行一个mysql查询并将该查询的结果抛出到带有while语句的单选按钮中。单选按钮的数量可能会有所不同,因此我无法通过POST功能执行一定数量的单选按钮。我努力做到这一点,以便用户可以选择其中一行然后选择" serverId"来自查询的数据被传递到test.php页面。任何帮助将不胜感激。感谢。

<html>
 <head>
  <title>Server Information</title>
 </head>
 <body>

<?php

//Starts the session and grabs the username from it
session_start();
$name=mysql_real_escape_string($_SESSION['username']);

include 'header.php';
include 'mysql_connect.php';

mysql_select_db('ist421test');

$result = mysql_query("SELECT userName, dateCreated, serverName, serverId, publicDNS, isRunning FROM server_tbl WHERE userName='$name' ORDER BY dateCreated DESC") or die(mysql_error());

if(mysql_num_rows($result) > 0): ?>
<form method="post" name="server_information" id="server_information" action="test.php">
<label>Server Information</label><br><br>
<table border='1'>
<tr>
    <th>Selection</th>
    <th>User Name</th>
    <th>Date Created</th>
    <th>Server Name</th>
    <th>Server Id</th>
    <th>Public DNS</th>
    <th>Running</th>
</tr>
<?php while($row = mysql_fetch_assoc($result)): ?>
<tr>
    <td><input method="post" type="radio" name="server" value="server_information" action="test.php"></td>
    <td><?php echo $row['userName']; ?></td>
    <td><?php echo $row['dateCreated']; ?></td>
    <td><?php echo $row['serverName']; ?></td>
    <td><?php echo $row['serverId']; ?></td>
    <td><?php echo $row['publicDNS'] ?></td>
    <td><?php echo $row['isRunning']; ?></td>
</tr>
<?php endwhile; ?>
</table>
<input type="submit" name="server_stop" value="Stop Server"/>
<input type="submit" name="server_terminate" value="Terminate Server"/>
</form>
<?php endif; ?>

</body>
</html>  

1 个答案:

答案 0 :(得分:1)

好的,有几条建议。

首先,对于无线电输入,从值标签中删除“server_information”并粘贴到serverID echo中。例如。

<input type="radio" name="server" value="<?php echo $row['serverId']; ?>" />

请注意,methodaction属性已被删除。它们仅适用于form元素。

现在就去吧。只能选择一个单选按钮,并且只有一个服务器ID应该POST到表单中。

您可以使用test.php访问$_POST['server']上的POST变量。