Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

add item to cart not working

Status
Not open for further replies.

mancroft

Programmer
Joined
Oct 26, 2002
Messages
267
Location
GB
I am using the form and php code below to add an item to a shopping cart but it isn't working.



Any suggestions please?



Many thanks.



Code:
<?php

include(&quot;db.php&quot;);


// Get a connection to the database
$cxn = mysql_connect($dbServer, $dbUser, $dbPass, $dbName) or die(mysql_error()); 
  
//select database 
$db = mysql_select_db(&quot;koscart&quot;, $cxn)  or die(mysql_error()); 

//add record
$sql = (&quot;insert into cart(cookieId, ITEMID, QTY) values('&quot; . GetCartId() . &quot;', $ITEMID, $QTY)&quot;) or die(mysql_error());

//execute sql query
$sql_result = mysql_query($sql , $cxn) or die(mysql_error());
 
ShowCart();

?>

<form action=&quot;[URL unfurl="true"]https://se4.g.com/~k/ShoppingBagForm.php&quot;[/URL] method=&quot;POST&quot;>
              <input type=&quot;hidden&quot; name=&quot;id&quot; value=&quot;1247001&quot;>
              <table border=&quot;0&quot; width=&quot;126&quot;>
                <tr align=&quot;right&quot;> 
                  <td width=&quot;56&quot;><strong>QTY </strong></td>
                  </tr>
                <tr align=&quot;right&quot;> 
                  <td><select name=&quot;QTY&quot; size=&quot;1&quot;>
                      <option selected>1</option>
                      <option>2</option>
                      <option>3 </option>
                      <option>4</option>
                      <option>5</option>
                      <option>6</option>
                      <option>7</option>
                      <option>8 </option>
                      <option>9</option>
                    </select></td>

</tr>
                <tr align=&quot;right&quot;> 
                  <td colspan=&quot;2&quot;><input
type=&quot;image&quot; name=&quot;I1&quot; src=&quot;../Images/ADD-TO-CART.jpg&quot;
align=&quot;bottom&quot; border=&quot;0&quot; width=&quot;126&quot; height=&quot;45&quot;> </td>
                </tr>
              </table>
            </form>
 
Have you checked out the register_global setting? This is a common nuissance by the fact that since PHP 4.2.0 the setting fro register_globals is by default off.
The real culprit is probably the older books that give examples that assume register_globals is on.


Refer to the posted vars using $_POST['QTY'].
I would also suggest to check before creating a record if a valid quantity and article have been selected.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top