medusa eyeofskadi
medusa eyeofskadi

Reputation: 7

Get data in modal by clicking add button

enter image description here

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?

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

  $(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

enter image description here

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

Upvotes: 0

Views: 57

Answers (2)

Melvic Gomez
Melvic Gomez

Reputation: 26

XAMPP and MySQL
In your php file:

 // 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', '[email protected]')";

 // 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.

Upvotes: 1

tringuyen
tringuyen

Reputation: 821

You can use:

if (isset($_GET['party'])) {
    echo $_GET['party'];
}
if (isset($_GET['partytwo'])) {
    echo $_GET['partytwo'];
}
......

Upvotes: 0

Related Questions