-4

今、私が得ているのは、私が入れたものと同じ値だけです。したがって、最初の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>";
4

3 に答える 3

2

PHP では、中かっこ{のない条件は、その後の1}のみを実行します。中かっこをいくつか追加する必要があります。

<?php

    $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 = '1'");
        while($row = mysqli_fetch_array($query)) {
            echo "<tr>";
            echo "<td> The price for insurance will be " . $row['insuranceprice'] . "</td>";
            echo "</tr>";
        }
        echo "</table>";
    } elseif ($_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>";

?>

その部分で何が起こっていたのかはわかりません<tr>が、ええ、これはあなたにとって良いスタートです.

于 2013-04-22T08:10:40.313 に答える
0

あなたifのステートメントには括弧がありません...これを試してください:

if(cond1){

}else if(cond2){

}
于 2013-04-22T08:10:48.187 に答える