doudao9915 2017-12-02 04:45
浏览 11
已采纳

使用php执行插入多个数据行

How can I insert this generated data using multiple send when requested because I made a code just for generating data but I don't know how to execute it to insert to database after it generated.

if (isset($_GET['action'])) {
$id = trim($_GET['current_balance']);
$limit = trim($_GET['limit']);
$con = new mysqli("localhost", "root", "", "neuro");
if ($con) {
    $sql = "select * from storage_data where current_balance = `enter code 
here`'$id' LIMIT 
$limit";
    $stmt = $con->query($sql);
    $val = '';
    if ($stmt) {
        if ($stmt->num_rows >= 1) {
            $i = 0;
            $val .= '<form method="post">'
                    .'<table class="table table-bordered table-advance 
 table-hover">'
                    . '<thead>'
                    . '<tr>'
                    . '<th>' . 'Details' . '</th>'
                    . '<th>' . 'CC' . '</th>'
                    . '<th>' . 'Sec' . '</th>'
                    . '<th>' . 'Balance' . '</th>'
                    . '<th>' . 'Email' . '</th>'
                    . '<th>' . 'Password' . '</th>'
                    . '<th>' . 'First Name' . '</th>'
                    . '<th>' . 'Last Name' . '</th>'
                    . '<th>' . 'Address' . '</th>'
                    . '<th>' . 'City' . '</th>'
                    . '<th>' . 'State' . '</th>'
                    . '<th>' . 'Zip' . '</th>'
                    . '<th>' . 'Phone' . '</th>'
                    . '</tr>'
                    . '<thead>'
                    . '<tbody>';
            while ($row = $stmt->fetch_assoc()) {
                $i++;
                $val .= '<tr>'
                        . '<td hidden>' . $i . '</td>'
                        . '<td>' . '<button class="btn btn-link btn-md" 
  data-toggle="modal" data-target="#myModal"><i class="fa fa-unlock"></i>
  </button>' . '</td>'
                        . '<td>' . $row["credit_card"] . '</td>'
                        . '<td>' . $row["security_code"] . '</td>'
                        . '<td>' . $row["current_balance"] . '</td>'
                        . '<td>' . $row["email"] . '</td>'
                        . '<td>' . $row["password"] . '</td>'
                        . '<td>' . $row["first_name"] . '</td>'
                        . '<td>' . $row["last_name"] . '</td>'
                        . '<td>' . $row["address"] . '</td>'
                        . '<td>' . $row["city"] . '</td>'
                        . '<td>' . $row["state"] . '</td>'
                        . '<td>' . $row["zip_code"] . '</td>'
                        . '<td>' . $row["phone_number"] . '</td>'
                        . '</tr>';

            }
            $val .= '<tbody></table></form>';
            echo $val;
        } else {
            $val .= "<p class='error'>No Data Found</p>";
            echo $val;
        }
      }
    }
  }
  • 写回答

2条回答 默认 最新

  • draj30958 2017-12-02 05:20
    关注

    You need to use prepared query for inserting the data in your table.

    I don't know exactly in which table you want to insert data but below query will help that you need to add within your while loop to insert all data whatever comes in foreach.

    // prepare and bind User Query
    $queryUsers = $conn->prepare("INSERT INTO 
    UserTable(user_login,user_pass,name) VALUES (?, ?, ?)");
    $queryUsers->bind_param("sss",$email,$upass,$uname);
    
    // execute Users Query
    $queryUsers->execute();
    
    // Close Connections
    $queryUsers->close();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集