0

Hi friends I am is a beginner in AJAX so I am Facing some problem which is I am unable to take the values from the header of the page which was sent be $_GET method ..Help me Please to find out the Solution

here is my PHP Code

<?php include '../../db_connect/connection.php'; ?>

<?php

$select = "SELECT * FROM leave_requests WHERE teacher_name = '$teacher_id' ORDER BY id DESC";
$select_result = mysqli_query($connection,$select);
while ($row = mysqli_fetch_assoc($select_result)) {
    $date = $row['date'];
    $teacher = $row['teacher_name'];
    $days = $row['days'];
    $reason = $row['reason'];
    $status = $row['status'];
    $type_of_leave = $row['type_of_leave'];

    $principal_remarks = $row['principal_remarks'];
    $id = $row['id'];
    ?>

    <td><?php echo $date; ?></td>
    <td><?php echo $days; ?></td>
    <td><?php echo $type_of_leave; ?></td>
    <td><?php echo $reason; ?></td>


    <td><?php echo $status; ?></td>
    <td><?php echo $principal_remarks; ?></td>
    </tr>

<?php
} ?>

and this is my incomplete AJAX code

<script type="text/javascript">
$(document).ready(function(){
    $.ajax({
        url:'display_leave_request_response.php',
        data:
    });
});
</script>

how can I grab the values which is comming in a get request in the header using Ajax please explain

sorry for coping the things since the system is not accepting the question so I have to do this

if there is any mistakes in the code then please explain it to me

Barmar
  • 741,623
  • 53
  • 500
  • 612
ABDUL GAFFAR
  • 11
  • 1
  • 2

1 Answers1

0

Set the data: option to an object containing the parameters you want to send:

data: { teacher_id: some_variable }

Then in PHP you can use:

$teacher_id = $_GET['teacher_id'];

You should also learn to use a prepared statement instead of substituting the $teacher_id variable directly into the SQL, to prevent SQL injection. See How can I prevent SQL injection in PHP?

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • I want that dynamically so any other solution for this sir – ABDUL GAFFAR Aug 24 '18 at 19:19
  • You mean `123` should be a dynamic value? That was just an example, you can get it dynamically from an input or dropdown. – Barmar Aug 24 '18 at 19:21
  • I already changed the answer. I replaced it with `some_variable`. You just need to set the variable, e.g. get it from an input. – Barmar Aug 25 '18 at 21:52