How to insert multiple row from textarea to multiple column?

我怕爱的太早我们不能终老 提交于 2021-01-29 21:39:09

问题


I have this code from index.php :

<?php 
require("../inc/config.php");
$url = $_GET['url'];
?>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
</head>
<body>
<form method="" action="">
    <textarea type="text" class="form-control" id="ketqua" name="ketqua" value="" required="" placeholder="Name|Url" rows="6"></textarea>
    <input type="text" class="form-control" id="link" name="link" required="" value="<?php echo $url ?>">
    <button type="button" class="btn btn-success" name="insert-data" id="insert-data" onclick="ThemTap()">Add</button>

</form>

<script type="text/javascript">
    function ThemTap() {
        var ketqua = $("#ketqua").val();
        var link = $("#link").val();
        $.ajax({
            type: "POST",
            url: "api.php",
            data: {
                action: 'ThemTap',
                ketqua: ketqua,
                link: link
            },
            dataType: "JSON",
            success: function(data) {
                $("#message").html(data);
                $("p").addClass("alert alert-success");
            },
            error: function(err) {
                alert(err);
            }
        });

    }
</script>

This is my api.php .I think my code is missing or missing in this section and I don't know how to solve it:

<?php
include('../inc/config.php');
if($_POST['action'] == 'ThemTap') {
$ketqua=$_POST['ketqua'];
$string = $ketqua;
$HuuNhan = explode('|',$string);
$link=$_POST['link'];
$stmt = $DBcon->prepare("INSERT INTO tap(tap,link,player) VALUES(N'".$HuuNhan[0]."', N'$link',N'".$HuuNhan[1]."')");
mysqli_query($conn,"UPDATE phim SET updatephim = updatephim + 1 WHERE link = '$link'");
if($stmt->execute())
{
if (mysqli_query($conn, $sql)) {

    }
$res="<div class='alert alert-success'>Đã thêm tập <b>".$HuuNhan[0]."</b> thành công !</div>";
  echo json_encode($res);
}
else {
  $error="<div class='alert alert-danger'>Thêm không thành công</div>";
  echo json_encode($error);
}
}
?>

I tried running it as follows: From text area

EP1|Link1
EP2|Link2
EP3|Link3

But it only inserts a row:

EP1|Link

And not insert EP2|Link2 and EP3|Link3 Please correct my source code so I can add many different rows, thank you very much!

来源:https://stackoverflow.com/questions/56128028/how-to-insert-multiple-row-from-textarea-to-multiple-column

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