php help
The purpose of my code is that when one clicks the button 'add to cart', the product name is stored in an array that is acting as a cart. Then i have another function, that when i click the button 'show cart' , it should show all the elements added in the array but it is not working, pls help <html> <head> </head> <body> <button onclick="showCart()">show cart</button> <?php session_start(); $conn =mysql_connect('127.0.0.1','root','123','shop'); //mysql Connection $result=mysql_query("select * from bookshop.books"); //sql statement ?> <?php while($row = mysql_fetch_array($result)){ ?> //while loop to enable access of data in database. <div> <img src="<?php echo $row['images']; ?>"> <button onclick="cart()">Add to cart</button> </div> <?php $cars = array(); //establishes an array echo '<script>'; echo 'function'.' '.'cart(){'; array_push($cars,"gg"); // adds elements to array echo 'alert("Your product was added");'; echo '}'; echo 'function'.' '.'showCart(){'; $arrlength = count($cars); // getting length of array for($counter = 0; $counter< $arrlength; $counter++) { // displays products in array echo 'alert('.$cars[$counter].');'; } echo '</script>'; } ?> </body> </html>