gpt4 book ai didi

php - 如何在单击按钮时将数据插入数据库?

转载 作者:行者123 更新时间:2023-11-30 23:48:02 25 4
gpt4 key购买 nike

我有一个模式,可以读取如下代码中的值。当我单击模式中的提交按钮时,是否可以将 $row3['first_name'] 等值插入到数据库中?我对此进行了研究,但我没有看到太多关于它的信息,因为它们主要使用文本字段。

<a href="#" class="btn btn-success hidden" id="request" data-toggle="modal" name="req" data-target="#basicModal">Request from Lender</a>
</br></br>

<form action="" method="post">
<div class="modal fade" id="basicModal" tabindex="-1" role="dialog" aria-labelledby="basicModal" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
<h4 class="modal-title" id="myModalLabel"><?php
print $row3['title'] . ' from ' . $row3['first_name'] . ' ' . $row3['last_name'];
?></h4>
</div>
<div class="modal-body">
<p>Are you sure you want to borrow <b> 1 x <?php
print $row3['title'];
?></b> from <b> <?php
print $row3['first_name'];
?> <?php
print $row3['last_name'];
?></b> for <b id="total"></b> cogs?
</br></br> You will be required to collect and return this item to <?php
print $row3['houseno'];
?> <?php
print $row3['address1'];
?> <?php
print $row3['postcode'];
?>.
</br></br> <?php
print $_GET[$from];
?> Your cogs will not be transferred to <?php
print $row3['first_name'];
?> until you have confirmed you wish to proceed following the lenders decision!</p>
</div>

<div class="modal-footer">
<button type="submit" value="submit" class="btn btn-success">Register</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>


</div>
</div>
</div>
</form>

最佳答案

您需要调用一个方法,将要插入数据库的值传递给它。

例子:

<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

$sql = "INSERT INTO MyGuests (firstname, lastname, email)
VALUES ('John', 'Doe', 'john@example.com')";

if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
?>

关于php - 如何在单击按钮时将数据插入数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28245201/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com