我有一个模态,可以读取下面代码中的值。当我点击模态中的提交按钮时,是否可以将$ 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>
答案 0 :(得分:-1)
您需要调用一个方法,将要插入的值传递给数据库。
示例:
<?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();
?>