2017-06-01 46 views
1

我試圖從插入HTML標籤中選擇一個值到MySQL:MySQL的:從選擇標記插入值成爲截斷

<select name="venuesend"> 
    <option value="37">LATINO SPORTS CLUB</option> 
    <option value="38">RED HOOK VISION CENTER</option> 
    <option value="39">ANTHOLOGY FILM ARCHIVES</option> 
    <option value="40">HUMMINGBIRD STUDIOS</option> 
    <option value="41">THE PRODUCERS CLUB</option> 
</select> 

所以,如果選擇LATINO SPORTS CLUB37的價值應該被髮送到MySQL 。但是,目前,發佈到MySQL的值始終是3。所以,我猜這是因爲什麼原因被截斷的。

這是我的PHP和HTML表單:

<?php 

      //if "submit" is clicked 
      if(isset($_POST['upload2'])) { 


       //check if image files were uploaded 
       foreach($_FILES['images']['error'] as $err){ 
        switch ($err){ 
         case UPLOAD_ERR_NO_FILE: 
          echo 'No file sent.'; 
          exit; 
        } 
       } 

       //iterate through each image file uploaded 
       for($x=0; $x<count($_FILES['images']['tmp_name']); $x++){ 


        //THIS IS WHERE VENUESEND IS POSTED 

        $screeningID2 = $_POST['venuesend'][$x]; 
        $file_name = $_FILES['images']['name'][$x]; 
        $file_tmp = $_FILES['images']['tmp_name'][$x]; 

        .... 

         //SQL statement and Posting 
         $sql2 = "INSERT INTO screeningImages (screeningId, imageURL) VALUES ('$screeningID2', '$file_name')"; 
         mysqli_query($db, $sql2); 
        } else{ 
         echo "Only images can be stored."; 
        } 
       } 
      } 

     ?> 

     //HTML Form 
     <form method="post" action="screenings-admin.php" enctype="multipart/form-data"> 


     //SELECT 

     <select name="venuesend"> 
      <option value="37">LATINO SPORTS CLUB</option> 
      <option value="38">RED HOOK VISION CENTER</option> 
      <option value="39">ANTHOLOGY FILM ARCHIVES</option> 
      <option value="40">HUMMINGBIRD STUDIOS</option> 
      <option value="41">THE PRODUCERS CLUB</option> 
     </select> 


      //Images Upload 
      <input type="file" id="imageUpload" name="images[]" multiple="" onchange="javascript:updateList()"/> 

      //submit button 
      <input type="submit" name="upload2" value="Upload" id="upload2"> 
     </form> 

回答

1

的問題是,您試圖訪問一個字符串(37)的一個陣列,您呼叫$screeningID2 = $_POST['venuesend'][$x];

<select> POSTs通過選定的$_POST[id];你實際上並不需要參考$x可言的,只需要:

$screeningID2 = $_POST['venuesend'];

你得到3未來通過,因爲$_POST['venuesend']已經是字符串37,和你基本上是在拍攝第一字符的字符串。

希望這會有所幫助! :)

0

部分代碼不清楚,但這應該從外觀上解決問題。

$screeningID2 = $_POST['venuesend'][$x] 

$screeningID2 = $_POST['venuesend]; 

隨着[$x]末,你想存儲/讀取存儲在變量中的整個字符串的字符。試試這段代碼並將我們更新回來,這樣我們可以看到是否修復了它。