Why am I not receiving any response from my PHP page and no other errors?

General Tech Bugs & Fixes 2 years ago

1 1 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 28 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (1)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

 

I have 2 pages, practice.php and addtocart.php. In practice.php, I gather info from a form and send the info using AJAX to addtocart.php. This page then connects to the database and inserts my values. However I am not receiving any response from addtocart.php and no data is being inserted in the database.

I have been trying to figure out the problem but cannot seem to find it. Please help.

practice.php

   //form from which addtocart is being called
     <form id="mehendicones">
      Color: <input list="mehendi_color" class="mehendi_color" 
         id="mehendi_color1">
                <datalist id="mehendi_color">
                    <option value="Black">
                    <option value="White">
                    <option value="Brown">
                    <option value="Dark Red"> 
                datalist>
                    
<p id="price">17p> Quantity<input type="number" min="5" max="15" id="quantity_mehendi_color" step="1"> <input type="submit" value="ADD TO CART" style="text-align:center;" onclick="addtocart()" > form> function addtocart() { var request = new XMLHttpRequest(); var url = "addtocart.php"; request.open("POST", url, true); request.setRequestHeader("Content-Type", "application/x-www-form- urlencoded"); request.onreadystatechange = function () { if (request.readyState === 4 && request.status === 200) { alert(request.response); } }; var pdetails = "mehendi cones"; var pquantity = document.forms["mehendicones"] ["quantity_mehendi_color"].value; var pcolor = document.forms["mehendicones"] ["mehendi_color1"].value; var price = document.getElementById("price").innerHTML; var data = ({ "pdetails": pdetails, "pquantity": pquantity, "pcolor": pcolor, "price": price }); request.send(data); }

addtocart.php

                                                
                                                
1 views
0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.