0
如果複選框被選中,我應該使用什麼函數來獲取「Y」,如果沒有,則使用「N」。這是添加到SQL語句中的嗎? 我猜這是一個if/else,但我無法弄清楚。用於生成SQL結果的複選框選項
這裏是我的複選框,其中一些可以單獨選擇:
<label class="timetable-q">Data Projector</label>
<input type="hidden" id="proj_check" name="proj_check" value="Y"/>
<input type="checkbox" id="proj_check" name="proj_check" value="N"/>
<label class="timetable-q">Whiteboard</label>
<input type="hidden" id="white_check" name="white_check" value="Y"/>
<input type="checkbox" id="white_check" name="white_check" value="N"/>
<label class="timetable-q">OHP</label>
<input type="hidden" id="ohp_check" name="ohp_check" value="Y"/>
<input type="checkbox" id="ohp_check" name="ohp_check" value="N"/>
<label class="timetable-q">Wheelchair Access</label>
<input type="hidden" id="wheel_check" name="wheel_check" value="Y"/>
<input type="checkbox" id="wheel_check" name="wheel_check" value="N"/>
<label class="timetable-q">Lecture Capture</label>
<input type="hidden" id="cap_check" name="cap_check" value="Y"/>
<input type="checkbox" id="cap_check" name="cap_check" value="N"/>
<input type="submit" value="submit">
</p>
</form>
這是我的PHP:
<?php
$numeroOption= $_POST['numero'];
$selectOption = $_POST['parkname'];
$query = "SELECT * FROM `ROOMS` WHERE `Capacity` < '$numeroOption' AND `Park` LIKE '$selectOption%'";
$result = mysql_query($query);
echo $result;
if ($result == FALSE) die ("could not execute statement $query<br />");
</php>
感謝您的幫助!
複選框將出現在你的'$ _POST'數組中。 –
[您的腳本存在SQL注入攻擊風險。](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) –
如果可以的話,您應該[停止使用'mysql_ *'函數](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php)。 [這些擴展](http://php.net/manual/en/migration70.removed-exts-sapis.php)已在PHP 7中刪除。瞭解[編寫](http://en.wikipedia.org/ wiki/Prepared_statement)語句[PDO](http://php.net/manual/en/pdo.prepared-statements.php)和[MySQLi](http://php.net/manual/en/mysqli.quickstart .prepared-statements.php)並考慮使用PDO,[這真的很簡單](http://jayblanchard.net/demystifying_php_pdo.html)。 –