sql - PHP: How to receive multiple values with ajax?


I have a pagepractice2.html in which a customer selects the product, color and quantity. After the user submits, the values are sent along with the product price and balance to another pageaddtocart.php via ajax.

Theaddtocart.php page receives those values, connects to the database and inserts those values. However,addtocart.php is not receiving those values and no values are visible in the alerts messages in the code below.

I think there is a problem in theaddtocart.php page on lineif(getenv('REQUEST_METHOD') == 'POST') but I do not know how to fix it:

      function addtocart(price){
      var productdetails=document.forms['mehendicones'].value;
      var pcolor=document.getElementById('mehendi_color').value;
    var pquantity=document.getElementById('quantity_mehendi_color').value;
         var bal=price*pquantity;
             var ajax=new XMLHttpRequest();
        if(this.readyState==4 && this.status==200){

        include 'includes/database.php';

           // I think there is an issue with the post call here
           if(getenv('REQUEST_METHOD') == 'POST'){

        $sql="INSERT INTO ".$nam." 
                 (pdetails,price,pquantity,pcolor,bal) VALUES 

        if(mysqli_num_rows($result) > 0){
            echo "added to cart";
            echo "couldnot add to cart..try again";

People are also looking for solutions to the problem: Using PHP Google Photos Api with Server-To-Server communication


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.