Add to cart (table) value not working

hi, im making an eCommerce store, i have have add to cart button working, the data for size and qty ads to the table, however, the model and product id do not. ive used the get method to get the product from the men page to the item page as shown here.

<?php
include 'mysql.php';
 $show_men="SELECT DISTINCT model, id,  price,image FROM products WHERE id='1' ";
 $query_men=mysqli_query($conn,$show_men);
  while($row=mysqli_fetch_array($query_men,MYSQLI_ASSOC)){
 echo '<br><br><table class="table"><tbody>
  <tr>
    <div><center><img class="img-responsive" src="../images/'.$row['image'].'" width="400" height="300"></center><br>
    <center><strong>'.$row['model'].'</strong><br><br><strong>Price:£    '.$row['price'].'</strong><br><br>
    <a href="../php/item.php?id1='.$row['id'].'" class="btn btn-default">More Info</a><br><br><strong></center></div><hr>
    </tr>
</tbody>
</table>';

 }
 ?>



this is the part on the item page. 


$custid = $_SESSION['custid'] ;
$price = $_POST['price'];
$productid=$_GET['id1'];
$size = $_POST['size'];
$qty = $_POST['qty'];
$model = mysqli_real_escape_string($conn, stripslashes($_POST['model']));
$now = date("Y-m-d H:i:s");


$sql = "INSERT INTO cart (custid, price, product_id, size, qty, model, created) VALUES ('" . $custid . "','" . $price . "', '" . $product_id . "', '" . $size . "', '" . $qty . "', '" . $model . "', '" . $now . "')";

	$result = mysqli_query($conn, $sql);
	if ($result == 1) {
		$res = "Added to cart";
	} else {
		$res = "Error saving cart data";
	}
  }

?>

there is something i have missed, if anyone can spot it id be greatful. thanks

There’s something off about your quotes in this line when you concatenate the variable. When you hover your mouse over the link, does the value of the id show up?

it does work tho, it passes info from men.php to item.php, the problem is while on item php it only pulls info for the one product while adding to cart even tho the other items are showing on the item.php page. its only adding id 1 to the table regardless of what id is shown on item.php

Typo for the product id:

$productid=$_GET['id1'];
... then ...
$sql = "INSERT INTO cart (custid, price, product_id, size, qty, model, created) 
VALUES ('" . $custid . "','" . $price . "', '" . $product_id . "', '" . $size . "', '" . 
$qty . "', '" . $model . "', '" . $now . "')";

$productid is not the same as $product_id.

Is there more code to that item.php? I can’t see where all the $_POST variables are coming from, if you are calling it from the link in your first bit of code.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.