sql将文本字符串存储为"数组"

时间:2017-06-09 12:05:20

标签: php sql forms

我发现了一个奇怪的错误,只发生在我的多种形式中的一种中,每种形式都以相同的方式使用,但是$codering = ['RF-013.12'];存储"数组"在我的桌子上?并且它旁边的字段应该是18但是存储值为0.
我想我在这里遗漏了一些东西。有人可以查看我的代码吗?谢谢! enter image description here

<

?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.";

4 个答案:

答案 0 :(得分:1)

你可以改变这个:

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

到此:

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

我认为在这种情况下你不需要数组到你的数据库中所以将数组变量更改为简单的字符串来解决你的问题

如果要将数组插入数据库,我建议您使用 json_encode

示例:

json_encode($yourArray);

答案 1 :(得分:0)

在这里创建数组。 []是数组语法

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

你需要传递像这样的字符串

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

答案 2 :(得分:0)

也许,因为您将包含一个元素的数组传递给数据库。 你桌子的结构是什么意思? 如果您尝试存储数组,请尝试使用带有现有表的引用的外表。

如果您想将RF-013.12保存为字符串,只需使用$codering = "RF-013.12";即可。 如果您有一个RF-013.12作为键的数组,请尝试引用该值。

格尔茨。

答案 3 :(得分:0)

这是正常的。当你这样做时:

$codering = ['RF-013.12'];

与:

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

因此,如果你尝试像字符串一样使用你的数组,那么php会写 array

如果你想存储[某事](带[]字符的字符串),你需要:

$codering = "[something]";

如果你真的需要存储一个数组,你可以序列化他。

示例:

serialize

string serialize ( mixed $value )

json_encode

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