简体   繁体   English

在php和mysql中多次插入(插入)

[英]multiple insertion in php and mysql (insert into)

I have a form that inserts some data in two tables 我有一个在两个表中插入一些数据的表单

<form name="modulo" method="post" action="inseriscio.php">
                Nordine&nbsp;<input id="nor" name="nor" value="Nordine"><br>
                Data ordine<input type="date" id="datao" name="dao" value="Data Ordine"><br>    
                Data consegna<input type="date" id="datac" name="dac" value="Data consegna"><br>
                <div id="contenitore">
                    <?php
                    $pro = 'sito';
                    $dd = mysqli_connect('localhost', 'root', '', $pro);
                    $re = mysqli_query ($dd,"SELECT Codice, Nome FROM prodotti");
                    echo"<div class='box'>";
                    echo"Prodotto";
                    echo"<select class='inse' name='po'>";
                    while($row=mysqli_fetch_array($re)){
                            echo"<option value=".$row['Codice'].">".$row['Nome']."</option>";}
                    echo"</select>";
                    echo"<br>";
                    echo"Quantit&agrave; <textarea name='qua' rows='1' cols='4'></textarea></div><br>";
                    ?> 
                             </div>
                    <br><button type="submit" id="ok">OK!</button><br>
                </form><input type="text" class ="num" id="num" name="num" value="numero"><button id = "aggi" onClick="agg()">Aggiungi</button>

This is the form. 这是表格。 Using the "aggiungi," I create other select and textarea via a script (the number of new tag is given from the keyboard). 使用“ aggiungi”,我通过脚本创建了其他select和textarea(新标签的数量由键盘给出)。 Until everything is ok but when I fill out the form and send to the php page that just takes a value of select and textarea and not all. 直到一切正常,但是当我填写表格并发送到php页面时,该页面只接受select和textarea的值,而不是全部。 So if I have 5 not fit all 5 of the values that I enter but only one. 因此,如果我有5个不适合我输入的所有5个值,而只有一个。

<?php
        $nordine = $_POST['nor'];
        $datao = $_POST['dao'];
        $datac = $_POST['dac'];
        $prodotto = $_POST['po'];
        $quantita = $_POST['qua'];

        $data = 'sito';
        $db = mysqli_connect('localhost', 'root', '', $data);
        $result = mysqli_multi_query ($db, "INSERT INTO ordini (Nordine,DataO,DataC) VALUES('$nordine','$datao','$datac')");

        $result1 = mysqli_multi_query ($db, "INSERT INTO ordpro (Prodotto, Ordini, Quantita) VALUES('$prodotto','$nordine','$quantita')");
        echo"<p>
        Hai inserito un nuovo record <a href='ordini.php'> torna alla home </a>
    </p>";
    ?>

php code I hope I was clear thank you php代码,我希望我很清楚谢谢

Can I clarify you are naming your new selects and textarea in the script? 我可以澄清一下您要在脚本中命名新选择的内容和文本区域吗?

"(the number of new tag is given from the keyboard)" ? “(新标签的数量由键盘给出)”?

so the newly create select and textarea have a new name? 所以新创建的select和textarea有一个新名称吗? ie. 即。

<select name='po' + currentIndex

and

<textarea name='qua' + currentIndex

If you aren't,you are only accessing the first 'po' and 'qua' form elements in your post handling code. 如果不是这样,则只能访问后期处理代码中的第一个“ po”和“ qua”表单元素。 If I understood your problem correctly. 如果我正确理解您的问题。

You can use mysqli_multi_query like this :- 您可以像这样使用mysqli_multi_query:

` sql = "INSERT INTO ordini (Nordine,DataO,DataC) VALUES('$nordine','$datao','$datac');"; sql =“在ordini中插入(Nordine,DataO,DataC)VALUES('$ nordine','$ datao','$ datac');”;

sql .= "INSERT INTO ordpro (Prodotto, Ordini, Quantita)VALUES('$prodotto','$nordine','$quantita')"; sql。=“插入到ordpro中(Prodotto,Ordini,Quantita)VALUES('$ prodotto','$ nordine','$ quantita')”;

if ($mysqli->multi_query($query)) { 如果($ mysqli-> multi_query($ query)){
}` }`

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM