【问题标题】:Radio Button POST issue单选按钮 POST 问题
【发布时间】:2014-05-10 05:38:42
【问题描述】:

这就是问题所在。我正在运行一个 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>  

【问题讨论】:

    标签: php mysql sql radio-button


    【解决方案1】:

    好的,有几个建议。

    首先,对于单选输入,从值标签中删除“server_information”并粘贴到您的 serverID 回显中。例如。

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

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

    现在试一试。只能选择一个单选按钮,并且只能将一个服务器 ID 发布到您的表单。

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

    【讨论】:

    • 这只会让它在字段中显示单选按钮,但由于 php 命令周围的引号,它不再显示记录,只是空格。任何想法。
    • 您可以在浏览器中查看页面源代码并粘贴它生成的代码吗? (也许更新你上面的问题)
    • 我错了。我道歉。它实际上是在 serverid 字段中显示单选按钮,并将 serverid 中的数据推送到下一个字段中。但它现在工作正常,只是它没有在与单选按钮相同的字段中显示 serverid....
    • 好的,那听起来很容易。只需将&lt;td&gt; 单元格中的数据重新排列到正确的位置即可。
    • 谢谢。一切都整理好了。
    猜你喜欢
    • 2014-12-30
    • 2015-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多