单击“添加”按钮以模态获取数据

时间:2018-04-06 01:46:30

标签: php jquery

enter image description here

如果我在href中点击带有id和名称的添加按钮(如上图所示),在获取PHP中的$ _GET等模态数据后如何分配变量?

模态

     <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

  $(document).ready(function(){
    $(".party").click(function(event){
        event.preventDefault();
     var puttingdata = $(this).attr("href");
       $("#puthere").text(puttingdata);
    });
});

这将显示,我不知道如何指定保存在数据库中

enter image description here

<span id="puthere" class="w3-large" style="text-transform: capitalize;"><b></b></span>

2 个答案:

答案 0 :(得分:1)

XAMPP和MySQL
在你的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();

检查数据库中是否有添加的记录。

答案 1 :(得分:0)

您可以使用:

{{1}}