2016-08-09 62 views
0
<?php 
session_start(); 
include_once "Dbconnect.php"; 
if(isset($_POST['btn_up'])){ 
    $email = $_POST['sn']; 
    if($email == ''){ 
    echo 'there was an error'; 
    }else{ 
    echo $email; 
    echo "something happened"; 
    } 
} 
var_dump($email); 
?> 
<!DOCTYPE html> 
<html> 
<head> 
<title> Admin </title> 
</head> 
<body> 

    <form method='post'> 
    <label for="select">School name</label> 
    <select name="sn"> 
     <option value="-" selected data-default>-</option> 
     <?php 
      $query = mysql_query("SELECT * FROM users WHERE school = 'sn'"); 
      while($rowtwo = mysql_fetch_array($query)){ 
       ?> 
       <option value="<?php echo $rowtwo['email']; ?>"><?php echo $rowtwo['email']; ?></option> 
       <?php 
      } 
     ?> 
    </select> 

<button type="submit" name='btn_up'>up</button> 
</form> 

</body> 
</html> 

我正在製作管理頁面,所以這只是代碼的一部分。在觀衆方面一切看起來不錯,但是當我從下拉列表中選擇一個值並按下「btn_up」時,代碼不會將用戶電子郵件保存在變量$ email中,這就是爲什麼它會檢查它是否爲空,因爲它是告訴我沒有任何東西可以保存到價值中。那麼,如何保存從下拉列表中選擇的任何值? 後續代碼var_dump()給了我這個錯誤如何從更改下拉框中獲取選定的值php和html

有一個Errorstring,則(0) 「」

+0

請包括'的var_dump($ _POST);'在PHP腳本的開頭,重複相同的過程,並向我們顯示輸出。 –

+0

這是一個錯字'WHERE school ='sn''你忘記了'$'符號。投票結束。你正在尋找一個'sn'字符串。這個問題本身並不能保證「答案」。 –

+0

sn是在數據庫中的名字@ Fred-ii- – Nick1615

回答

-1
<script src="jquery-3.1.0.js"></script> 
    <script> 
     $(function() { 
      $('#selectnumber').change(function(){ 
       alert('.val() = ' + $('#selectnumber').val() + ' AND html() = ' + $('#selectnumber option:selected').html() + ' AND .text() = ' + $('#selectnumber option:selected').text()); 
      }) 
     }); 
    </script> 
<select id="selectnumber"> 
      <option value="1">one</option> 
      <option value="2">two</option> 
      <option value="3">three</option> 
      <option value="4">four</option> 
     </select> 

Click to see out put screen

謝謝... :)

+0

這是如何解決OP的問題的? –

相關問題