So I have a website http://streamplus.gansaikhanshur.com/test.php where it displays movie informations. I want the user to be able to add multiple items to the cart. Now once you click add to cart it automatically brings the user to the cart page.
my test.php file is below
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<br />
<div class="container" style="width:700px;">
<?php
$connect = mysqli_connect("localhost", "gshur_gshur", "password", "gshur_root");
$query = "SELECT * from gshur_root.final_dataset";
$result = mysqli_query($connect, $query);
if(mysqli_num_rows($result) > 0)
{
while($rows = mysqli_fetch_array($result))
{
?>
<form method="post" action="testcart.php?action=add&id=<?php echo $rows["id"]; ?>">
<div style="border:1px solid #333; background-color:#f1f1f1; border-radius:3px; padding:15px;" align="center">
<img src="pictures/<?php echo $rows['movie_paths']; ?>"/><br />
<button type="submit" name="add_to_cart" value="<?php echo $rows['id'] ?>">Add to Cart</button>
</div>
</form>
<?php
}
}
?>
<div style="clear:both"></div>
<br />
</div>
<br />
</body>
</html>
and my testcart.php file displays the picked movie and removes it. But I also want the user to be able to see the number of movies to purchase and remove multiple movies in the testcart.php page. (below is the code)
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<br />
<div class="container" style="width:700px;">
<?php
$connect = mysqli_connect("localhost", "gshur_gshur", "password", "gshur_root");
$query = "SELECT * from gshur_root.final_dataset";
$result = mysqli_query($connect, $query);
if(isset($_POST["add_to_cart"])){
$connect = mysqli_connect("localhost", "gshur_gshur", "password", "gshur_root");
$id = $_POST["add_to_cart"];
$movie_path = "SELECT movie_paths from gshur_root.final_dataset WHERE id = $id";
$result = mysqli_query($connect, $movie_path);
while ($row = $result->fetch_assoc()) {
echo '<img src="pictures/'.$row['movie_paths'].'" width="182" height="268">';
?>
<form method="post" action="testcart.php?action=remove&id=<?php echo $rows["id"]; ?>">
<div style="border:1px solid #333; background-color:#f1f1f1; border-radius:3px; padding:15px;" align="center">
<img src="pictures/<?php echo $rows['movie_paths']; ?>"/><br />
<button type="submit" name="remove" value="<?php echo $rows['id'] ?>">Remove</button>
</div>
</form>
<?php
}
}
if (isset($_POST['remove'])){
$id = $_POST["add_to_cart"];
unset($id);
echo "<script>alert('Product has been Removed!')</script>";
echo "<script>window.location = 'testcart.php'</script>";
}
?>
<div style="clear:both"></div>
<br />
</div>
<br />
</body>
</html>
I am using a button tag. How do I implement this functionality while still using the button tag? I want to be able to click on multiple add to card button then click on cart page to see my selected movies.