How to insert multiple value and Multiple rows from textarea to MySQL using PHP?

会有一股神秘感。 提交于 2021-01-28 07:44:55

问题


Now i submit this to textarea :

1|Value

This insert to database :

-------------------
Column1 | Column2
1       | Value
-------------------

Now I want to add these results to multiple lines by pressing the enter key, please help me add it This is my HTML index code :

<form method="POST" action="add.php">
<div class="form-group">
    <label for="chonphim">Film:</label>
  <select class="form-control" name="chonphim" id="chonphim">
<option value="kono-yo-no-hate-de-koi-wo-utau-shoujo-yu-no_JZ93Q">Phim Kono Yo no Hate de Koi wo Utau Shoujo YU-NO</option>
  </select>
</div>
<div class="form-group">
    <label for="player">Multiple row and data:</label>
    <textarea class="form-control" id="player" name="player" rows="4" placeholder="1|Value1
2|Value2
3|Value3"></textarea>
  </div>
<center>
<div class="form-group">
<button style="margin-top: 15px;" class="btn btn-primary active" type="submit" >Add value</button></div></center>
</form>

This is add.php

$chonphim=$_POST['chonphims'];
$player = escape_string($_POST['player']);
$player1 = explode("|", $player);
$tapphim = $player1[0];
$linkplayphim = $player1[1];
$sql2 = "UPDATE vohuunhan_film SET settime = settime + 1 WHERE link = '$chonphim'";
$sql88 = "INSERT INTO vohuunhan_episode (tap, linkplay, id_film)
VALUES (N'$tapphim', N'$linkplayphim', N'$chonphim');";
if ($connect->query($sql88) === TRUE && $connect->query($sql2) === TRUE) {
    echo "Success !"; 
} else {
    echo "Error: " . $connect->error;
}

I want :

1|Value1
2|Value2
3|Value3

Insert to database :

-------------------
Column1 | Column2
1       | Value1
2       | Value2
3       | Value3
-------------------

来源:https://stackoverflow.com/questions/57015837/how-to-insert-multiple-value-and-multiple-rows-from-textarea-to-mysql-using-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!