I've been struggling with this since months, and finally got to the point I need to fix it on my project.
The thing is, I'm sending an ajax request to a php file where I need to read the current $_GET['user_id'] value in order to insert a query. But php just won't read $_GET['user_id'] value from the current URL address, like if it doesn't exist.
This is driving me crazy, since I don't know any other methods that can achieve the desired result which is following a user account.
Here's the piece of code, which is meant for explanation purposes only:
// PHP
<?php
require_once "db.php";
$query = "INSERT INTO followers(follower, following) ";
$query .= "VALUE('{$_SESSION['id_user']}','{$_GET['user_id']}' )";
$result = mysqli_query($connect_db, $query);
?>
// AJAX
<script>
$('.js-follow_user_btn').click(function(){
follow_unfollow_action();
});
function follow_unfollow_action(){
$.ajax({
type: 'POST',
url: 'follow_user.php',
success: function(data) {
alert('done');
}
});
}
</script>