【发布时间】:2011-02-08 18:09:33
【问题描述】:
我有一个接受以下输入的表单:
名称:IBM
表面(以 m^2 为单位):9
楼层:(复选框1)
电话:(复选框2)
网络:(复选框3)
按钮发送到下一个 php 页面。
当我按下提交按钮时,上述所有这些值都显示在表格中。
表中正确显示了前两个(姓名和姓氏)。
问题出在复选框上。如果我选择第一个复选框,则表中的值应显示为 1。如果它没有被选中,表中的值应该是空的。
echo "<td>$Name</td>"; // works properly
echo "<td>$Surface</td>"; // works properly
echo "<td>....no idea for the checkboxes</td>;
我的 php 代码的某些部分带有变量:
<?php
if (!empty($_POST))
{
$name= $_POST["name"];
$surface= $_POST["surface"];
$floor= $_POST["floor"];
$phone= $_POST["telefoon"];
$network= $_POST["netwerk"];
if (is_numeric($surface))
{
$_SESSION["name"]=$name;
$_SESSION["surface"]=$surface;
header("Location:ExpoOverzicht.php");
}
else
{
echo "<h1>Wrong input, Pleasee fill in again</h1>";
}
if(!empty($floor) && ($phone) && ($network))
{
$_SESSION["floor"]=$floor;
$_SESSION["phone"]=$phone;
$_SESSION["network"]=$network;
header("Location:ExpoOverzicht.php");
}
}
?>
带表格的第二页:
<?php
$name= $_SESSION["name"];
$surface= $_SESSION["surface"];
$floor= $_SESSION["floor"];
$phone= $_SESSION["phone"];
$network= $_SESSION["network"];
echo "<table class=\"tableExpo\">";
echo "<th>name</th>";
echo "<th>surface</th>";
echo "<th>floor</th>";
echo "<th>phone</th>";
echo "<th>network</th>";
echo "<th>total price</th>";
for($i=0; $i <= $_SESSION["name"]; $i++)
{
echo "<tr>";
echo "<td>$name</td>"; // gives right output
echo "<td>$surface</td>"; // gives right output
echo "<td>...</td>"; //wrong output (ment for checkbox 1)
echo "<td>...</td>"; //wrong output (ment for checkbox 2)
echo "<td>...</td>"; //wrong output (ment for checkbox 3)
echo "<td>....</td>";
echo "</tr>;";
}
echo "</table>";
<form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post" id="form1">
<h1>Vul de gegevens in</h1>
<table>
<tr>
<td>Name:</td>
<td><input type="text" name="name" size="18"/></td>
</tr>
<tr>
<td>Surface(in m^2):</td>
<td><input type="text" name="surface" size="6"/></td>
</tr>
<tr>
<td>Floor:</td>
<td><input type="checkbox" name="floor" value="floor"/></td>
</tr>
<tr>
<td>Phone:</td>
<td><input type="checkbox" name="phone" value="phone"/></td>
</tr>
<tr>
<td>Network:</td>
<td><input type="checkbox" name="network" value="network"/></td>
</tr>
<tr>
<td><input type="submit" name="verzenden" value="Verzenden"/></td>
</tr>
</table>
由于我必须翻译它,因此可能存在一些拼写错误。 最好的祝福。
【问题讨论】:
-
你的html代码看起来像???
-
添加了表单html代码。一切都在 2 个 php 文件中。
标签: php