2014-03-04 84 views
-5
<?php 
include("dbconfig.php"); 
if(isset($_POST['type'])== "enquiry") 
{ 
    query for enuiry; 

} 
else{ 
    query for enroll; 
} 

?> 
<form action="dropd.php" method="POST"> 
<select name="type"> 
<option>Please select:</option> 
<option value="enquiry">Student enquiry</option> 
<option value="enroll">Student enrollment</option> 
<input type="submit" name="submit" value="SUBMIT"> 
</select> 
</form> 

嗨..我想運行兩個不同的SQL查詢基於下拉選擇。我不知道該怎麼做。我對PHP很新鮮。請指導我。基於下拉值運行SQL查詢

+2

谷歌是你的朋友... – zozo

+0

甚至專家PHP不能回答你的問題...... – user1844933

+0

開放數據庫連接,建立查詢,執行查詢?我沒有看到問題在這裏。 –

回答

1
<?php 
include("dbconfig.php"); 
if(isset($_POST['submit'])) 
{ 
    if(isset($_POST['type'])) 
    { 
     if($_POST['type'] == "enquiry") 
     { 
      Query 
     } 
     elseif($_POST['type'] == "enroll") 
     { 
      Query 
     } 
     else 
     { 
      echo "Please select enquiry or enrollment"; 
     } 
    } 
    else 
    { 
     echo "Please select an option"; 
    } 

} 

?> 
<form action="dropd.php" method="POST"> 
<select name="type"> 
<option value="">Please select:</option> 
<option value="enquiry">Student enquiry</option> 
<option value="enroll">Student enrollment</option> 
<input type="submit" name="submit" value="SUBMIT"> 
</select> 
</form> 
+0

在這個答案中,HTML部分存在錯誤,不知道它是如何有用的。 –

0

您的代碼應該是這樣的:

<?php 
include("dbconfig.php"); 
if(isset($_POST['submit'])){ 
    if(isset($_POST['type']) && $_POST['type'] == "enquiry") 
    { 
    query for enuiry; 

    } else { 
    query for enroll; 
    } 
} 
?> 
<form action="dropd.php" method="POST"> 
<select name="type"> 
    <option value=''>Please select:</option> 
    <option value="enquiry">Student enquiry</option> 
    <option value="enroll">Student enrollment</option> 
</select> 
<input type="submit" name="submit" value="SUBMIT"> 
</form>