2017-04-02 90 views
1

點擊「刪除」(提交)後:我可以告訴它處理表單,因爲我收到錯誤「您忘了選擇要刪除的供應商」。html表單發佈不發送可變數據

表單本身是使用PHP生成的。當我檢查HTML輸出時,我發現的值爲。但是,當它進入POST時,沒有任何結果。我正在測試和使用本地主機,因此除了現有的操作鏈接之外,我不確定我還能修改哪些內容。

我有完全相同的代碼在另一個刪除窗體,它工作正常。我從字面上複製了另一個表單來創建這個表單,然後改變了SQL /變量名稱。

form with open drop down form with closed drop down

PHP代碼:

#delete vendor 
require('includes/mysqli_connect.php'); 

if ($_SERVER['REQUEST_METHOD'] == 'POST') { 
    $errors = array(); //array to collect errors 

    //check to ensure fields are filled out 
    if (!empty($_POST['vendor'])) { 
     $vendor = trim($_POST['vendor']); 
    } 
    else { 
     $errors[] = "<p>You forgot to select a vendor to delete</p>"; 
    } 

    if (empty($errors)) { 
     //insert information into appt table 
     $query = "UPDATE vendors_t SET active = 0 WHERE vendorID = $vendor;"; 
     $result = mysqli_query($dbc, $query); 
     if($result){ 
      echo '<div class="alert alert-success" role="alert">'; 
      echo '<h2>Thank you!</h2>'; 
      echo '<p> Your request to delete vendorID ' . $customerID . 'has been completed </p></div>'; 
     } else { 
      echo "Error updating record: " . mysqli_error($dbc); 
     } 
    } else{ 
     echo '<div class="alert alert-danger" role="alert"><br>'; 
     echo '<h2>Errors Detected</h2>'; 
     echo '<p>The following errors occured:<br/>'; 
     foreach ($errors as $msg) { 
      echo "$msg<br/>\n"; 
     } 
     echo '</p><p>Please try again. </p></div>'; 
    } 

} 

HTML代碼

<div class="container standout" > 
    <div class="col-lg-12"> 
     <h2>Delete a vendor</h2> 
     <p> Please select a vendor to delete.</p> 
    </div> 
    <div class="row"> 
     <form action="index.php?pagelet=deletevendor" method="post"> 
      <div class="form-group col-md-4"> 
       <label for="vendor">Vendors</label> 
       <select name="vendor" class="form-control"> 
        <option name="vendor" selected disabled>Choose here</option> 
        <?php 
         $query = "SELECT vendorID, contactFname, contactLname, businessName FROM vendors_T WHERE active = 1;"; 
         $result = mysqli_query($dbc, $query); 

         while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {     
          echo '<option name="vendor" value="'.$row['vendorID'].'">' 
            .$row['vendorID'].' '.$row['businessName'] 
            .' '.$row['contactFname'].' '.$row['contactLname'] 
           .'</option>'; 
         }?> 
       </select> 
       <br> 
       <br> 
       <input class="btn btn-primary" id="submit" type="submit" value="Delete"> 
      </div> 
     </div> 
    </form> 
</div> 
+0

我們可以看到表單的標記,我高度懷疑你沒有名爲「供應商」的字段。 – mayersdesign

+0

從<選項名稱=「供應商」選擇禁用**選擇**從這裏選擇 –

+0

從選項(<選項名稱=「供應商」)刪除名稱='供應商',並添加值屬性,而不是刪除選中。 –

回答

0

你的選項名稱應該是供應商ID(我相信)的值,當然不是「供應商」。

0

從選項中刪除name =「vendor」&刪除選中的兩個工作。

刪除名稱=「供應商」後 - 我添加選擇回來,它仍然工作。 謝謝!