sql >> Database >  >> RDS >> Mysql

Meerdere rijen uit tekstgebieden invoegen in MySQL

U had enkele html-fouten en een onveilige uitvoering van de query. Probeer dit:HTML

<form id="form1" name="form1" method="post" action="func/insert.php">
<table>
<tr>
<td>text 1</td>
<td>:</td>
<td><textarea class="custom" rows="10" cols="80" name="text1" id="text1" required></textarea></td>
</tr>
<tr>
<td>text 2</td>
<td>:</td>
<td><textarea class="custom" rows="10" cols="80" name="text2" id="text2" required>
</textarea></td>
</tr>
</table>
</form>

PHP

include"connection.php";
if(isset($_POST['text1'])){
    if(strpos($_POST['text1'], "\n")){
        $entrytext1 = explode("\n",$_POST['text1']);
    }
    else{
        $entrytext1 = array($_POST['text1']);
    }
    foreach ($entrytext1 as $linetext1){
        $stmt = $mysqli->prepare("INSERT INTO data(text1,text2)VALUES(:text1, :text2)");
        $result = $stmt->execute(array('text1' => $linetext1, 'text2'    =>  $_POST['text2']));
        if ($result){
        echo"<script>alert(\"Success ...\");window.location='../index.php'</script>";
        }
        else{
            echo"<script>alert(\"Failed ...\");self.history.back()</script>";
        }
    }
}



  1. Een (trage) enorme WordPress-database versnellen

  2. Eenvoudige syntaxisfout in tabelquery?

  3. FOUT:null-waarde in kolom-ID schendt niet-null-beperking

  4. $wpdb->insert werkt niet. Geen foutbericht