<?php
$age1 = isset($_POST['age1']) ? $_POST['age1'] : false;
if ($age1 <= "18")
{
$sql = 'select * from events where type_id='.$id.' and id = 1 ';
}
else if (isset($_POST['age1']) > "18")
{
$sql = 'select * from events where type_id='.$id.'';
}
$tid = mysqli_query($conid, $sql);
?>
這裏是我的HTML代碼找不到輸出
<tr>
<td class="style1">Date of Birth:</td>
<td class="style2"><input type="text" name="dob" id="dob" class="form-control22" required autocomplete="off"></td>
</tr>
<tr>
<td class="style1">Age:</td>
<td class="style2"><input type="text" name="age1" id="age1" class="form-control22" autocomplete="off"></td>
</tr>
<tr>
<td class="style1">Event Type:</td>
<td class="style2">
<select name="event_id" class="ddl" id="event_id" onchange="geteventprice()">
<option value="0">--Select Event Type--</option>
<?php while($evt= mysqli_fetch_object($tid)){
echo '<option value="'.$evt->id.'">'.$evt->name.'</option>'; } ?>
</select>
</td>
選擇dob
活動將是展會。
18歲以下是不同的事件,超過18歲是不同的年齡。在上面的代碼中,我只能得到其他值之前。
假也將小於18改變在'''isset假($ _ POST [ 'AGE-1'])? $ _POST ['age1']:false;'''爲數值。 –
'if(isset($ _ POST ['age1'])>「18」)' – Peon
**警告**:使用mysqli時,應該使用[參數化查詢](http://php.net/manual /en/mysqli.quickstart.prepared-statements.php)和['bind_param'](http://php.net/manual/en/mysqli-stmt.bind-param.php)將用戶數據添加到您的查詢中。 **不要**使用字符串插值或連接來完成此操作,因爲您創建了嚴重的[SQL注入漏洞](http://bobby-tables.com/)。 **不要**將'$ _POST','$ _GET'或**任何**用戶數據直接放入查詢中,如果有人試圖利用您的錯誤,這可能會非常有害。 – tadman