Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

177
Views
Passing variable from JS using ajax to PHP undefined variable

I want to pass variable rating_index to the PHP code and send to database. Rating_index is set I'll not pass the code here because it is long, but right before AJAX i console.log(rating_index) and it has value(int). Add-review is a button that after click should send variable. In js script I am using AJAX :

$('#add-review').click(function(){
     $.ajax({
        url:"rating-data.php",
        method:"POST",
        data: {
            rating_index: rating_index
        },
        success:function(data)
        {
           
            console.log(data);
        }
    })
}

in my php file rating-data.php:

<?php 
    include 'connection.php';
    echo "work";
    echo $_POST["rating_index"];
?>

I got a console.log ('work') from PHP file and this error: Notice: Undefined index: rating_index in /Applications/XAMPP/xamppfiles/htdocs/bookwarm-app/rating-data.php on line 4

So it is getting my to php page but the variable are not passing correctly.

I was trying everything and I have no idea what is wrong and why this variable is undefined in php file. Thanks for any clue

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This is the problem in your code, sir

$user_name = $_GET["user_name"];
$user_rating = $_GET["rating_index"];
$user_review = $_GET["user_review"];

you're doing a $_POST request from Ajax and in php file you're getting values from $_GET.....?

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!