Hi guys i have been trying for days now to insert to variables into a table which are “$member_id” and “$product_idx” now for some reason if i echo them out before clicking the add button it displays the correct numbers but when i click the add button it seems to add 2, 0 into the database any help here is my code below:
i will be really grateful if you could help me as i have been struggling for days and its doing my head in i have a deadline on the project
[php]
session_start();
$member_id=$_SESSION[‘SESS_MEMBER_ID’];
include_once(‘connections/db101.php’);
$link_id = db_connect();
if(isset($busID)){
$productquery = “SELECT product_idx, business_id, product_name, image, description, price FROM products WHERE business_id=$busID AND active = 1”;
} else {
echo “Sorry This Shop has no products”;
}
$productresult = mysql_query($productquery, $link_id);
//Loop through products
while($productrow = mysql_fetch_array($productresult, MYSQL_ASSOC)){
$product_idx = $productrow['product_idx'];
$product_name = $productrow['product_name'];
$product_image = $productrow['image'];
$product_desc = $productrow['description'];
$product_price = $productrow['price'];
//Write Products
echo "<div class=\"productHold\">";
echo "<div class=\"productName\">".$product_name."</div>";
echo "<div class=\"productImage\">".$product_image."</div>";
echo "<div class=\"productDesc\">".$product_desc."</div>";
echo "<div class=\"productPrice\">£".$product_price."</div>";
?>
<form method="post" name="addtobudget" action="<?php echo $_PHP_SELF; ?>" />
<input type="submit" name="addtobudget" value="Add" id="<?php echo $product_idx; ?>" />
</form>
<?php
echo "</div>";
}
?>
<?php
require_once(‘update.php’);
if(isset($_POST[‘addtobudget’]))
{
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die(‘Could not connect: ’ . mysql_error());
}
$sql = "INSERT INTO clientSelection (client_id,product_id) VALUES (’$member_id’,’$product_idx’)";
mysql_select_db(‘weddingonthego’);
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not update data: ’ . mysql_error());
}
echo “Updated data successfully\n”;
mysql_close($conn);
}
?>[/php]