SQL INSERT INTO语法一个字段和多个值

时间:2017-12-23 20:36:47

标签: javascript php html sql drag-and-drop

JS extract
----------

 document.addEventListener("drop", function(event) {
            // prevent default action 
            event.preventDefault();
            // move dragged elem to the selected drop target
            if (event.target.className == "dropzone") {
                event.target.style.background = "#062c3c";
                dragged.parentNode.removeChild(dragged);
                event.target.appendChild(dragged);
                event.stopPropagation()
                    }
        }, false);

        function myFunction() {  
        document.getElementById("drop").addEventListener("submit", myFunction);
        }


html extract
------------


        <form action="data_ddexample2.php" method = "post" enctype="multipart/form-data" form id="interiorstyle">

        <div class="draggable" id ="draggable"><name="interiorstyle" value="Scandinavian"><img alt="Scandinavian" class="draggable" draggable="true" height="200" ondragstart="event.dataTransfer.setData" src="carda1.jpg" tabindex="1" width="200"></div>

        <div class="draggable" id ="draggable"><name="interiorstyle" value="Eclectic"><img alt="Eclectic" class="draggable" draggable="true" height="200" ondragstart="event.dataTransfer.setData" src="carda2.jpg" tabindex="2" width="200"></div>

        <div class="draggable" id ="draggable"><name="interiorstyle" value="Industrial"><img alt="Industrial" class="draggable" draggable="true" height="200" ondragstart="event.dataTransfer.setData" src="carda3.jpg" tabindex="3" width="200"></div>


    <div class="dropzone" input type="hidden" name ="dropzone1[]" id="dropzone1" multiple>
    <p>1<sup>st</sup> Preference</p>


PhP extract
-----------


        $dropzone1= $array["dropzone1"] = ['scandinavian', 'eclectic', 'industrial', 'vintage', 'minimalist', 'midcenturynodern', 'coastal', 'contemporary', 'traditional', 'bohemian', 'hollywoodglam', 'rustic', 'frenchcountry', 'transitional', 'none', 'other'];

        $dropzone2= $array["dropzone2"] = ['scandinavian', 'eclectic', 'industrial', 'vintage', 'minimalist', 'midcenturynodern', 'coastal', 'contemporary', 'traditional', 'bohemian', 'hollywoodglam', 'rustic', 'frenchcountry', 'transitional', 'none', 'other'];

        $comment = $_POST["comment"]; 

        $sql = "INSERT INTO task2ctest (dropzone1, dropzone2, comment)
                VALUES ('$dropzone1', '$dropzone2', '$comment')";


SQL Syntax error
----------------


        Notice: Array to string conversion in C:\xampp\htdocs\Testsdd\data_ddexample2.php on line 95

        Notice: Array to string conversion in C:\xampp\htdocs\Testsdd\data_ddexample2.php on line 95
        New record created successfully

问题
        评论发布正常,但只有“&#39; array&#39;发布到SQL而不是数组的实际div值。因此,总而言之,我只想将用户拖动的值的POST发布到名为dropzone1和dropzone2的div中。我假设这与INSERT INTO语法有关,但我可能错过了html或JS代码中的内容。

0 个答案:

没有答案