I am trying to make a cart system for a webshop. The form is supposed to post infomation to addtocart.php
but it is not posting the data and i have no idea why.
The form with the problem:
<?php
$query = "SELECT * FROM parts ORDER BY RAND() LIMIT 6";
$result = mysqli_query ($connect, $query);
while( $record=mysqli_fetch_array($result) ) {
$partnr=$record['partnr'];
$specs=$record['specs'];
$price=$record['price'];
echo '<div class="col-sm-4 col-lg-4 col-md-4">';
echo '<div class="thumbnail">';
echo '<img src="afb/'.$partnr.'.png" alt="">';
echo '<div class="caption">';
echo '<h4 class="pull-right">€'.$price.'</h4>';
echo "<h4><a href='item.php?id=".$partnr."'>".$partnr."</a>";
echo '</h4>';
echo '<p> '.$specs.'';
echo "<form class='form-signin' action='addtocart.php' method='POST' autocomplete='off'>";
echo "<input type='hidden' name=".$partnr." value=".$partnr.">";
echo "<input type='hidden' name=".$specs." value=".$specs.">";
echo "<input type='hidden' name=".$price." value=".$price.">";
echo "<input type='submit' value='Add to cart' class='btn btn-default'>";
echo "</form>";
echo '</div>';
echo '</div>';
echo '</div>';
}
?>
Contents of addtocart.php
<?php
session_start();
require_once('includes/connect.php');
$id = $_SESSION['id'];
$partnr = $_POST['partnr'];
$specs = $_POST['specs'];
$price = $_POST['price'];
echo $id;
echo $partnr;
echo $specs;
echo $price;
echo $_POST['partnr'];
echo $_POST['specs'];
echo $_POST['price'];
$query = "INSERT INTO cart (customer_id, partnr, specs, price, quantity) VALUES ('$id', '$partnr', '$specs', '$price', 1)";
mysqli_query ($connect, $query) or die ("Insert Failed");
echo 'window.location = "cart.php";';
?>
The result of addtocart.php
1Insert Failed