I have a problem with Submit buttons. I want to make a system like auto-alert subscribe.
But my second button with Subscribe is reddirect on the first page for purchase.php I tried to use formation in the second button
I know the problem is form action bcs i close after php cod, but i tried all option and i don't have any ideea.
If you have any suggestion without my system subscribe i listen. Thank you for help.
<?php
$error_code = "if (this.src != 'assets/default-product.png') this.src = 'assets/default-product.png';";
?>
<img class="no-drag product-image" src="<?php echo $product_image; ?>" onerror="<?php echo $error_code; ?>">
<h1 style="font-size: 25px; padding-bottom: 10px; padding-top: 20px;"><?php echo $product_name; ?></h1>
<h1 style="font-size: 20px; padding-bottom: 5px; padding-top: 5px;">Region: <?php echo $product_region_name; ?></h1>
<h1 style="font-size: 20px; padding-bottom: 5px; padding-top: 5px;">Type: <?php echo $product_type_name; ?></h1>
<h1 style="font-size: 20px; padding-bottom: 5px; padding-top: 5px;">Status: <?php echo $product_status_name; ?></h1>
<h1 style="font-size: 20px; padding-bottom: 5px; padding-top: 5px;">Categories: <?php echo $product_categories_name; ?> Champions</h1>
<h1 style="font-size: 20px; padding-bottom: 5px; padding-top: 5px;">Current Rank: <?php echo $product_ranked_name; ?></h1>
<h1 style="font-size: 20px; padding-bottom: 5px; padding-top: 5px;">Last Check: <?php echo $last_checked; ?></h1>
<form action="purchase.php" method="POST">
<input type="hidden" name="post_product_id" id="post_product_id" value="<?php echo $post_product_id; ?>"/>
<?php
if($total_product_stock == "0") {
echo '<h1 style="font-size: 40px; padding-bottom: 5px; padding-top: 5px;">There are currently Out of Stock </h1>';
echo '<p></p><br>';
echo '<h1 style="font-size: 20px; padding-bottom: 5px; padding-top: 5px;">Alert Stock Refill</h1>';
echo '<input type="email" name = "email"style= "width: 35%; text-align: center;"placeholder="Enter your email"required></p><br>';
echo '<button style="width: 20%;" type="submit2" value="submit2">Subscribe</button>';//END IF TOTAL STOCK IS 0
if (isset($_POST['submit2'])) { // Fetching variables of the form which travels in URL
$product_id = $post_product_id;
$email = $_POST['email'];
if ($email != '') {
$query = mysqli_query($conn, "insert into notif_stock(product_id, email_contact)
values ('$product_id','$email')");
echo "<br/><br/><span>Success Subscribed</span>";
}
}else{
echo "<br/><br/><span>Unsubscribed</span>";
}
}
else{
echo '';
echo ' <label for="requested_quantity">Quantity</label><br>';
echo '<input type="number" style="width: 125px;" class="form-control" name="requested_quantity" id="requested_quantity" min="1" max='.$total_product_stock.'" value="1"><br><br>';
echo '<p>There are currently '.$total_product_stock.' accounts in stock</p><br>';
echo '<button type="submit" name="buy" id="submit" value="buy">€'.$product_price.' each</button>';
echo '';
}//END ELSE
?>
</form>
<a href="index.php"><button>Back to Home</button></a>
</div>
</div></center>
<?php
include "footer.php";
?>