如何在请求时使用多个发送插入此生成的数据,因为我创建的代码仅用于生成数据,但我不知道如何执行它以在生成后插入数据库。
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;
}
}
}
}
答案 0 :(得分:0)
您需要使用准备好的查询在表格中插入数据。
我不确切地知道您要在哪个表中插入数据,但是在查询之下将有助于您在while循环中添加以插入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 :(得分:-2)
您可以使用以下代码将数据插入到sql中。
$servername="localhost";
$username="root";
$password="";
$db="login";//databasenam
//connection
$conn=new mysqli($servername,$username,$password,$db);
$sql=$conn->query("INSERT INTO tablename values(''$variables','$variables','$variables','$variables')");