现在我所得到的是与我所投入的价值相同的价值。所以它只是读取第一个if语句,就是这样,并输出相同的价格。意外的变量问题
$mysqli = new mysqli("localhost", "root", "", "insuredcars");
if ($_POST['formcar'] == '1' || $_POST['formage'] == '18' || $_POST['formNCD'] == '0' || $_POST['formPoints'] == '0')
{
$query = $mysqli->query("SELECT * FROM insurance WHERE insuranceid = '3'");
while($row = mysqli_fetch_assoc($query))
{
echo "<tr>";
echo "<td> The price for insurance will be " . $row['insuranceprice'] . "</td>";
echo "</tr>";
}
echo "</table>";
}
else if ($_POST['formcar'] == '6' || $_POST['formage'] == '18' || $_POST['formNCD'] == '0' || $_POST['formPoints'] == '0')
{
$query = $mysqli->query("SELECT * FROM insurance WHERE insuranceid = '2'");
echo "<tr>";
echo "<td> The price for insurance will be " . $row['insuranceprice'] . "</td>";
echo "</tr>";
echo "</table>";
}
else if ($_POST['formcar'] == '1' || $_POST['formage'] == '19' || $_POST['formNCD'] == '0' || $_POST['formPoints'] == '0')
{
$query = $mysqli->query("SELECT * FROM insurance WHERE insuranceid = '5'");
echo "<tr>";
echo "<td> The price for insurance will be " . $row['insuranceprice'] . "</td>";
echo "</tr>";
}
echo "</table>";
其中是错误,它是什么 – PSR 2013-04-22 08:09:06
添加括号但仍然得到错误:解析错误:语法错误,意想不到的'}'在第16行C:\ xampp \ htdocs \ search.php – 2013-04-22 08:20:34
考虑分离问题 - 不要在同一个脚本上混合使用MySQL,PHP和HTML:最终会得到无法维护且无法使用的代码。 – moonwave99 2013-04-22 10:05:37