[英]Get data in modal by clicking add button
If I click add button (like in above picture) with the id and name in href, how do I assign a variable after I get a data in modal like $_GET in PHP? 如果我单击添加按钮(如上图所示),其id和名称在href中,则在获取模态数据(如PHP中的$ _GET)后如何分配变量?
modal 语气
<tr>
<td class="w3-padding-16" style="text-transform: capitalize"><?php echo $first_nameparty ?></td>
<td class="w3-padding-16" style="text-transform: capitalize"><?php echo $last_nameparty ?></td>
<td class="w3-padding-16" style="text-transform: capitalize"><?php echo $middle_nameparty ?></td>
<td><a href="?party=<?php echo $resident_idparty ?>&partytwo=<?php echo $first_nameparty ?>&party3=<?php echo $last_nameparty ?>" class="w3-btn w3-green party">Add</a></td>
</tr>
js JS
$(document).ready(function(){
$(".party").click(function(event){
event.preventDefault();
var puttingdata = $(this).attr("href");
$("#puthere").text(puttingdata);
});
});
This is will show and I don't know how to assign to save in database 这将显示出来,我不知道如何分配保存在数据库中
<span id="puthere" class="w3-large" style="text-transform: capitalize;"><b></b></span>
XAMPP and MySQL XAMPP和MySQL
In your php file: 在您的php文件中:
// Initialize your variable that will catch for your form data
$first_nameparty="";
$middle_nameparty="";
$last_nameparty ="";
// Check the form data of your request
if (isset($_GET['Party']))
$first_nameparty = $_GET['Party'];
if (isset($_GET['Partytwo']))
$middle_nameparty = $_GET['Partytwo'];
if (isset($_GET['Party3']))
$last_nameparty = $_GET['Party3'];
// Database configuration
$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 STATEMENT (string)
$sql = "INSERT INTO tablename (field2, fieldname2, fieldname3)
VALUES ('John', 'Doe', 'john@example.com')";
// Execute the sql statement
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
// Close connection
$conn->close();
Check your database for the added record. 检查数据库中是否有添加的记录。
You can use: 您可以使用:
if (isset($_GET['party'])) {
echo $_GET['party'];
}
if (isset($_GET['partytwo'])) {
echo $_GET['partytwo'];
}
......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.