Im fairly new to php and ajax. I am trying to pass along a variable from jquery to a php page that is loaded up in a modal window.
I have php returning the table information for a bunch of users. Next to each users name, I have an edit button. I have jquery grabbing the data-id parameter of that button.
$(document).ready(function() {
$('.editButton').click(function(e){
e.preventDefault();
var getid = $(this).data('id');
Now I have a php form script that I want to load in a modal window when the "edit" button is clicked. The only way to do that is to make the button that opens the modal window an a tag and use href to call the php script. I want to pass along the variable "getid" to the php script that will use the value to run a query against the database to find the user that was clicked(the data-id parameter is generated by another php script which returns the id of that user). I tried many ways to send the ajax information to the external php script but no matter what I do, cant get it to work. Here is my ajax request:
$.ajax ({
url: '/extschedule.php',
data: {getid : getid},
type: 'POST',
success: function(data) {
alert('success');
}
}).error(function() {
Alert('Error');
Here is the php code on extschedule.php:
$connection = mysqli_connect(stuff);
$idVar = $_POST['getid'];
$sqledit = "SELECT * from database WHERE id = (".$idVar.")";
$result = $connection->query($sqledit);
while($row = $result->fetch_array(MYSQLI_ASSOC)){
$name = $row['name'];
$id = $row['id'];
$team = $row['team'];
$language = $row['language'];
$dedicatedHotel = $row['ded_hotel'];
$satStart = $row['Sat_start_time'];
$satEnd = $row['Sat_end_time'];..............yadda yadda
I tried using if(isset($_POST['getid']))) but that causes a ton of issues on the php side. Ive searched around a while but still cannot get to any resolution. Can someone help me with this? Thanks in advance!