Hi all,
I have the following form:
<form method="POST" action="vsadmin/addtocart.php">
<input type="hidden" name="movie_id" value="<?php print $rs["movie_id"]?>">
<input name="image" type="image" src="images/buy.gif" border="0">
<br/>
<br/>
<p align="center"><a href="JavaScript://" onClick="MM_openBrWindow('http://dvdrealm.com.au/emailfriend.php?id=<?php print $rs["movie_id"]?>','emailfriend','width=400,height=370'); return false"><?php print $xxEmFrnd?></a></p>
<?php print $xxQuant?>: <input type="text" name="new_qty" size="4" value="1">
</form>
what do i need to change in the addtocart.php or the include file function.php inorder to pass whatever value is in the "new_qty" input field?
Here is the addtocart.php script:
<?php
ob_start();
include ('functions.php');
session_start();
if (!empty($_POST['movie_id'])) {
$movie_id = $_POST['movie_id'];
// Starting a new cart session
if (!session_is_registered("cart")) {
$_SESSION['cart'] = array();
$_SESSION['items'] = 0;
$_SESSION['total_price'] = 0.00;
}
// Existing DVD in the cart + 1
if (!isset($_SESSION['cart'][$movie_id])) {
$_SESSION['cart'][$movie_id]++;
}
else {
$_SESSION['cart'][$movie_id] = 1;
}
$_SESSION['total_price'] = calculate_price($_SESSION['cart']);
$_SESSION['items'] = calculate_items ($_SESSION['cart']);
header ("Location: ../cart.php");
}
ob_end_flush();
?>
...and the functions.php script:
<?
function calculate_price($cart)
{
$_SESSION['price']=0.0;
if(is_array($_SESSION['cart']))
{
$connection=mysql_connect("localhost","","") or die('Could not connect to the database server');
$db = mysql_select_db("dvdrealm", $connection) or die ("Unable to select database.");
foreach($_SESSION['cart'] as $isbn => $qty)
{
$sql= "SELECT
movie_current_price
FROM
movie
WHERE
movie_id='$isbn'";
$sql_result = mysql_query($sql,$connection) or die ("Could not select data");
while ($row = mysql_fetch_row($sql_result))
{
$_SESSION['movie_current_price']= $row['0'];
}
$_SESSION['price'] += $_SESSION['movie_current_price']*$qty;
}
}
return $_SESSION['price'];
}
function calculate_items($cart)
{
$_SESSION['items']=0;
if(is_array($_SESSION['cart']))
{
foreach($_SESSION['cart'] as $movie_id => $qty)
{
$_SESSION['items'] += $qty;
}
}
return $_SESSION['items'];
}
?>
Cheers,
micmac