Using js with php- need help with code
The purpose of this code is when the button is clicked , the price of the product is taken from the database and added added to the sum and so on. It basically gives you the total price of the products. The price is not displaying , can someone tell me why please. (i know some tags are missing like the body and style tags, but i have them in my actual code and its still not working) Heres my code: <body> <h1>Shop</h1> <h2>This is the shop page</h2> <?php $servername = "Minato"; //changed for safety reasons $username = "naurto";//changed for safety reasons $password = "Shippuden";//changed for safety reasons $dbname = "shop"; //changed for safety reasons $conn = new mysqli($servername, $username, $password, $dbname); $sql="SELECT * FROM products where productID=1"; $result = mysqli_query($conn, $sql); while($row = mysqli_fetch_array($result)) // get all the data from the database you specified, and puts it an array { $photo=$row["image"]; echo'<div class="container">'; echo'<img src='.'"'.$photo.'"'.'class="image">'; echo'<div class="overlay">'; echo'<div class="text"><button onclick="cartFunction()" id="cartButton" >add to cart </button></div>'; echo'</div>'; echo '</div>'; } echo '<script>'; echo 'var'." ".'button=document.getElementById("cartButton");'; echo 'function'." ".'cartFunction(){'; echo 'var'." ".'sum=0;'; echo 'var'." ".'price='. $row["Price"].';'; echo 'price+=sum;'; echo 'price'; // meant to print price echo '}'; echo '</script>'; ?> </body>