I have a Dropdown list with Select with 1, 2, 3, 4, after select on of them it bust to refresh the page to what you select but it don't do it. Can you all see what the error is for me? I look over and over i don't see any error or it not the right on i need. Here All The Code On The Page
PHP Code:
<script language="php">
// find out what you want to do with the cart with action variable and act accordinly
global $action, $cartId, $itemId, $qty, $itemoptions, $shortdesc, $longdesc, $prodprice, $updater;
if($action == "add_item") {
AddItem();
ShowCart();
}
function AddItem()
{
global $eurocash, $cartId, $itemId, $qty, $itemoptions, $shortdesc, $longdesc, $prodprice, $prodtotalcost, $catId;
include "adminshop/config/shop_db.php";
$db = mysql_connect($host, $dbuser, $dbpass);
mysql_select_db($dbase,$db);
$result = mysql_query("select * from cart where cartId = '$cartId' and itemId = '$itemId' and itemoptions = '$itemoptions'");
$row = mysql_fetch_row($result);
$numRows = $row[0];
if($numRows == 0)
{
// This item doesn't exist in the users cart,
// we will add it with an insert query
$query = "INSERT INTO cart VALUES ('$cartId', '$itemId', '$qty', '$itemoptions', '$shortdesc', '$longdesc', '$prodprice', '$catId')";
$result = MYSQL_QUERY($query);
}
else
{
// This item already exists lets update it.
$query = "UPDATE cart set qty = qty + '$qty' where cartId = '$cartId' and itemId = '$itemId' and itemoptions = '$itemoptions'";
$result = MYSQL_QUERY($query);
}
}
function UpdateItem()
{
global $cartId, $itemId, $qty, $itemoptions, $shortdesc, $longdesc, $prodprice, $prodtotalcost;
// Updates the quantity of an item in the users cart.
// If the qutnaity is zero, then RemoveItem will be
// called instead
include "adminshop/config/shop_db.php";
$db = mysql_connect($host, $dbuser, $dbpass);
mysql_select_db($dbase,$db);
mysql_query("update cart set qty = '$qty' where cartId = '$cartId' and itemId = '$itemId' and itemoptions = '$itemoptions'");
}
function UpdateItemOption()
{
global $cartId, $itemId, $qty, $itemoptions, $shortdesc, $longdesc, $prodprice, $prodtotalcost, $prevoption;
include "adminshop/config/shop_db.php";
$db = mysql_connect($host, $dbuser, $dbpass);
mysql_select_db($dbase,$db);
$result = mysql_query("select * from cart where cartId = '$cartId' and itemId = '$itemId' and itemoptions = '$itemoptions'");
$row = mysql_fetch_row($result);
$numRows = $row[0];
if($numRows == 0)
{
// This items size doesn't exist in the users cart,
// we will update old with an insert query
mysql_query("update cart set itemoptions = '$itemoptions' where cartId = '$cartId' and itemId = '$itemId' and itemoptions = '$prevoption'");
}
else
{
mysql_query("update cart set qty = qty + '$qty' where cartId = '$cartId' and itemId = '$itemId' and itemoptions = '$itemoptions'");
mysql_query("delete from cart where cartId = '$cartId' and itemId = '$itemId' and itemoptions = '$prevoption'");
}
}
function RemoveItem()
{
global $cartId, $itemId, $qty, $itemoptions, $shortdesc, $longdesc, $prodprice, $prodtotalcost;
include "adminshop/config/shop_db.php";
$db = mysql_connect($host, $dbuser, $dbpass);
mysql_select_db($dbase,$db);
mysql_query("delete from cart where cartId like '$cartId' and itemId like '$itemId' and itemoptions like '$itemoptions'");
}
function EmptyCart()
{
global $cartId, $itemId, $qty, $itemoptions, $shortdesc, $longdesc, $prodprice, $prodtotalcost;
include "adminshop/config/shop_db.php";
$db = mysql_connect($host, $dbuser, $dbpass);
mysql_select_db($dbase,$db);
mysql_query("delete from cart where cartId like '$cartId'");
}
function ShowCart()
{
From everything i've been reading, this is not possible with PHP. PHP is client side, and run before the HTML page is loaded in the browser, as such it cannot react to butotn presses etc.
There is a very real possibility that I am wrong!
I have a Dropdown list with Select with 1, 2, 3, 4, after select on of them it bust to refresh the page to what you select but it don't do it. Can you all see what the error is for me? I look over and over i don't see any error or it not the right on i need.
From what I understand, you have a select box, and when you select the option, you want it to be done when you change the selection, i.e, the page reloads with the new information, updated in the database.
alternatively you could use a submit option, which is sometimes easier. onChange is sometimes better used for javascript and client side work.
Quick question, which version of PHP are you using ?
If I could have a clear clarrification of the question, I could rework my possible ideas of your problem