2017-06-09 68 views
-6

我發現了一個奇怪的錯誤,它只出現在我的許多表單中的一箇中,每個表單都以相同的方式使用,但$codering = ['RF-013.12'];在我的表中存儲「Array」?和它旁邊的字段應該是18,但存儲值爲0.
我想我在這裏錯過了一些東西。有人可以查看我的代碼嗎?謝謝! enter image description heresql將文本字符串存儲爲「數組」

< 

?php 
     if(isset($_POST['update'])) { 
      $dbhost = 'localhost'; 
      $dbuser = 'heijsdb_user'; 
      $dbpass = 'maus'; 

      $conn = ($GLOBALS["___mysqli_ston"] = mysqli_connect($dbhost, $dbuser, $dbpass)); 

      if(! $conn) { 
       die('Could not connect: ' . mysqli_error($GLOBALS["___mysqli_ston"])); 
      } 
//variable aanmaken van formulier 
       $controleur = $_SESSION["username"]; 
       $codering = ['RF-013.12']; 
       $revisie = ['18']; 
       $g11 = $_POST['11000']; 
       $g15 = $_POST['15000']; 
       $g110 = $_POST['110000']; 
       $g15c = $_POST['15000c']; 
       $g21 = $_POST['21000']; 
       $g25 = $_POST['25000']; 
       $g210 = $_POST['210000']; 
       $g25c = $_POST['25000c']; 
       $g31 = $_POST['31000']; 
       $g35 = $_POST['35000']; 
       $g310 = $_POST['310000']; 
       $g35c = $_POST['35000c']; 
       $g41 = $_POST['41000']; 
       $g45 = $_POST['45000']; 
       $g410 = $_POST['410000']; 
       $g45c = $_POST['45000c']; 
       $g61 = $_POST['61000']; 
       $g65 = $_POST['65000']; 
       $g610 = $_POST['610000']; 
       $g65c = $_POST['65000c']; 
       $g71 = $_POST['71000']; 
       $g75 = $_POST['75000']; 
       $g710 = $_POST['710000']; 
       $g75c = $_POST['75000c']; 
       $g81 = $_POST['81000']; 
       $g85 = $_POST['85000']; 
       $g810 = $_POST['810000']; 
       $g85c = $_POST['85000c']; 
       $g91 = $_POST['91000']; 
       $g95 = $_POST['95000']; 
       $g910 = $_POST['910000']; 
       $g95c = $_POST['95000c']; 
       $g9a1 = $_POST['9a1000']; 
       $g9a5 = $_POST['9a5000']; 
       $g9a10 = $_POST['9a10000']; 
       $g9a5c = $_POST['9a5000c']; 
       $g101 = $_POST['101000']; 
       $g105 = $_POST['105000']; 
       $g1010 = $_POST['1010000']; 
       $g105c = $_POST['105000c']; 
       $g111 = $_POST['111000']; 
       $g115 = $_POST['115000']; 
       $g1110 = $_POST['1110000']; 
       $g115c = $_POST['115000c']; 
       $g121 = $_POST['121000']; 
       $g125 = $_POST['125000']; 
       $g1210 = $_POST['1210000']; 
       $g125c = $_POST['125000c']; 
       $g131 = $_POST['131000']; 
       $g135 = $_POST['135000']; 
       $g1310 = $_POST['1310000']; 
       $g135c = $_POST['135000c']; 
       $g141 = $_POST['141000']; 
       $g145 = $_POST['145000']; 
       $g1410 = $_POST['1410000']; 
       $g145c = $_POST['145000c']; 
       $g151 = $_POST['151000']; 
       $g155 = $_POST['155000']; 
       $g1510 = $_POST['1510000']; 
       $g155c = $_POST['155000c']; 
       $g181 = $_POST['181000']; 
       $g185 = $_POST['185000']; 
       $g1810 = $_POST['1810000']; 
       $g185c = $_POST['185000c']; 
       $g191 = $_POST['191000']; 
       $g195 = $_POST['195000']; 
       $g1910 = $_POST['1910000']; 
       $g195c = $_POST['195000c']; 
       $g201 = $_POST['201000']; 
       $g205 = $_POST['205000']; 
       $g2010 = $_POST['2010000']; 
       $g205c = $_POST['205000c']; 


      $sql = "INSERT INTO weegschaal(controleur, codering, revisie, inpak1000, inpak5000, inpak10000, inpak5000c, kruiden1000, kruiden5000, kruiden10000, kruiden5000c, linco601000, linco605000, linco6010000, linco605000c, linco301000, linco305000, linco3010000, linco305000c, vleugel1000, vleugel5000, vleugel10000, vleugel5000c, meijnborst1000, meijnborst5000, meijnborst10000, meijnborst5000c, meijnpoot1000, meijnpoot5000, meijnpoot10000, meijnpoot5000c, divers1000, divers5000, divers10000, divers5000c, td1000, td5000, td10000, td5000c, batchborst1000, batchborst5000, batchborst10000, batchborst5000c, organen1000, organen5000, organen10000, organen5000c, dienst1000, dienst5000, dienst10000, dienst5000c, inpakreserve1000, inpakreserve5000, inpakreserve10000, inpakreserve5000c, foodpoten1000, foodpoten5000, foodpoten10000, foodpoten5000c, foodborst1000, foodborst5000, foodborst10000, foodborst5000c, reservedini1000, reservedini5000, reservedini10000, reservedini5000c, reserve1dini1000, reserve1dini5000, reserve1dini10000, reserve1dini5000c, inpaktafel1000, inpaktafel5000, inpaktafel10000, inpaktafel5000c) VALUES 
      ('$controleur','$codering','$revisie','$g11', '$g15', '$g110', '$g15c', '$g21','$g25','$g210','$g25c','$g31','$g35','$g310','$g35c','$g41','$g45','$g410','$g45c','$g61','$g65','$g610','$g65c','$g71','$g75','$g710','$g75c','$g81','$g85','$g810','$g85c','$g91','$g95','$g910','$g95c','$g9a1','$g9a5','$g9a10','$g9a5c','$g101','$g105','$g1010','$g105c','$g111','$g115','$g1110','$g115c','$g121','$g125','$g1210','$g125c','$g131','$g135','$g1310','$g135c','$g141','$g145','$g1410','$g145c','$g151','$g155','$g1510','$g155c','$g181','$g185','$g1810','$g185c','$g191','$g195','$g1910','$g195c','$g201','$g205','$g2010','$g205c') "; 
      mysqli_select_db($GLOBALS["___mysqli_ston"], 'heijsdb'); 
      $retval = mysqli_query($conn , $sql); 

      if(! $retval) { 
       die('Could not update data: ' . mysqli_error($GLOBALS["___mysqli_ston"])); 
      } 
      echo "Formulier verstuurd."; 
+0

codering字段是\t \t文本latin1_swedish_ci – maus

+0

瞭解準備語句,以防止SQL注入 – Jens

+0

如果您啓用錯誤報告並檢查您的日誌,我幾乎可以*保證*您有「*數組到字符串轉換*」錯誤。 – Qirel

回答

0

這很正常。當你這樣做:

$codering = array('RF-013.12'); 

因此,如果您嘗試使用您的陣列像串,PHP寫陣列代替:

$codering = ['RF-013.12']; 

爲相同。

如果你想儲存[東西](帶[]字符的字符串),你需要:

$codering = "[something]"; 

如果你真的需要存儲陣列,您可以同時連載了他。

實施例:

serialize

string serialize (mixed $value) 

json_encode

string json_encode (mixed $value [, int $options = 0 [, int $depth = 512 ]]) 
1

你可以改變這一點:

$codering = ['RF-013.12']; 
$revisie = ['18']; 

這樣:

$codering = 'RF-013.12'; 
$revisie = '18'; 

我認爲你不需要陣列到你的數據庫在這種情況下,如此改變數組變成簡單的字符串來解決你的問題

如果你要插入一個數組我勸數據庫您使用 json_encode

例子:

json_encode($yourArray); 
0

這裏您創建陣列。 []是數組語法

$codering = ['RF-013.12']; 
$revisie = ['18']; 

你需要傳遞的字符串這樣

$codering = 'RF-013.12'; 
$revisie = '18'; 
0

也許,因爲你傳遞一個包含一個元素到你的數據庫的數組。 你的桌子的結構說什麼? 如果您嘗試存儲數組,請嘗試在現有表上使用帶有引用的外部表。

如果要將RF-013.12保存爲字符串,只需使用$codering = "RF-013.12";即可。 如果您有一個RF-013.12作爲密鑰的陣列,請嘗試引用該值。

Greetz。