Jump to content

image as submit button


lional

Recommended Posts

Hi All

I have a small issue that I can't seem to figure out.

I am busy creating a shopping cart, and I have one button called update cart. The aim of this is that if the user sets the quantityu to 0 or any other number for that matter, the cart will be updated with that quantity. It seems to work perfectly if I use the submit for the input type but not the image type.

Can someone please explain this to me. I am attaching the code,

 

Thanks

 

Lional

 

<?php

session_start();

?>

<body text="#000000" vlink="#000000" alink="#ff0000" link="#0000ff" bgcolor="#ffffff" background="banners/test1.gif" bgproperties="fixed">

<?php

// This page displays the contents of the cart

// check to see if the form has been submitted (to update the cart).

if (isset($_POST['submit'])) {

foreach ($_POST['qty'] as $key => $value) {

if (($value == 0) AND (is_numeric($value))) {

unset ($_SESSION['cart'][$key]);

} elseif (is_numeric($value) AND ($value > 0)) {

$_SESSION['cart'][$key] = $value;

}

}

}

// check if the shopping cart is empty

$empty = TRUE;

if (isset($_SESSION['cart'])) {

foreach($_SESSION['cart'] as $key => $value) {

if (isset($value)) {

$empty = FALSE;

}

}

}

// Display the cart if it is not empty

if (!$empty) {

include 'includes/conn_db.php';

// Retrieve all of the information for the products in the cart

$query = 'SELECT * FROM products WHERE prod_code IN (';

foreach ($_SESSION['cart'] as $key => $value) {

$query .= $key . ',';

}

$query = substr ($query, 0, -1) . ') ORDER BY prod_name ASC';

$result = mysql_query($query);

 

// create a table and a form

print <<<TOP

<table summary="" bgcolor="#960232" width="610">

<tr>

<td nowrap align="center"><font face="Arial" size="2" color="#d2d1cf"> <b>YOUR SHOPPING CART</b></font></tr></table>

<table summary="" width="600" border="1" style="border-color:#960232">

<tr>

<td>

<table border="0" width="600" cellpadding="3">

<tr>

<td align="left" width="230"><font face="arial" size="2" color="#5e5d5d"><b>Product</b></font></td>

<td align="center" width="70"><font face="arial" size="2" color="#5e5d5d"><b>Qty</b></font></td>

<td align="right" width="120"><font face="arial" size="2" color="#5e5d5d"><b>Unit Price</b></font></td>

<td align="right" width="120"><font face="arial" size="2" color="#5e5d5d"><b>Line Total</b></font></td>

</tr>

<form action="view_cart.php" method="post">

TOP;

// Print each item

$total = 0; // total cost of the order

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {

 

// Calculate the total and subtotals

$subtotal = $_SESSION['cart'][$row['prod_code']] * $row['unit_price'];

$total += $subtotal;

$subtotal = number_format($subtotal, 2);

$total = number_format($total, 2);

// print the row

print <<<ROW

<tr>

<td align="left"><font face="arial" size="2" color="#5e5d5d">{$row['prod_name']}</font></td>

<td align="center"><input type="text" size="3" name="qty[{$row['prod_code']}]" value="{$_SESSION['cart'][$row['prod_code']]}"></td>

<td align="right"><font face="arial" size="2" color="#5e5d5d">R {$row['unit_price']}</font></td>

<td align="right"><font face="arial" size="2" color="#5e5d5d">R $subtotal</font></td>

</tr>

ROW;

} // end of the WHILE loop

// print the footer and close the table and the form

print <<<FOOTER

<tr>

<td></td><td></td>

<td align="right"><font face="arial" size="2" color="#5e5d5d"><b>Total:</b></font></td>

<td align="right"><font face="arial" size="2" color="#5e5d5d"><b>R $total</b></font></td>

</tr>

</table><table width="600">

<tr><br><td width="100%" valign="top" align="center"><a href="royal_arch_companions_can__pay_o.php"><img src="buttons/more_purchases.gif" alt="More Purchases" border="0"></a><a href="checkout.php"><img src="buttons/checkout.gif" alt="Checkout" border="0"></a><input type="image" src="buttons/update_cart.gif" name="submit"></form>

</td></tr></div>

FOOTER;

} else {

echo '<p>Your cart is empty!';

}

?>

 

 

 

<tr>

<td></td>

</tr>

</table>

 

Link to comment
https://forums.phpfreaks.com/topic/54425-image-as-submit-button/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.