Hello, I am having some trouble assigning a value to a variable inside a switch statement. What I am trying to do here is trip an error if the user has already added an item in the shopping cart. The While and Foreach loops work perfectly fine. The problem is that the value of variable $error does not get passed outside of the case. As a result, I cannot get the error message to display. I really need to get this to work and any help is appreciated. The code looks something like this:
Code: switch ($action) {
case 'add' :
{
if ($_SESSION['CartID'] == "")
{
$query = 'INSERT INTO ShopCart( UserID )VALUES("' . $UserID . '")';
mysql_query($query, $db) or die(mysql_error($db));
$Shop = 'SELECT ShopCartID FROM ShopCart WHERE UserID = "' . $UserID . '" ORDER BY ShopCartID ASC LIMIT 1';
$Cart = mysql_query($Shop);
$ShopCart = mysql_fetch_row($Cart);
$_SESSION['CartID'] = $ShopCart[0];
}
$query = 'SELECT ProductID FROM ShopCartLine WHERE ShopCartID = "' . $_SESSION['CartID'] . '"';
$result=mysql_query($query, $db) or die(mysql_error($db));
//$row = mysql_fetch_row( $result );
while($var = mysql_fetch_array($result))
{
foreach ($var as $i) {
if ($i == $ProductID) {
$error = 1; //TRIP THE ERROR HERE!
echo "<script type='text/javascript'>window.top.location='http://amarcy2.db-class.ids.uic.edu/shopcart.php';</script>";
}
}
}
}
The code being used to display the error message is as follows:
Code:
if ($error == 1) {
echo '<p>You already have this item in your basket!</p>';
}
What am I missing here? Help!
Hello all!. I can't seem to get this working right. Well - it renders right, but something is going wrong. It's a set of filters for events. The filter marked "type" (category) works
MS Access data into a html table
Hi everyone, I am quite a novice at php but I have created some helpful scripts that fetch datafrom a ms access database that is used by our POS program at work ( a spa/salon)My boss asked me to
Inserting a variable in a link
I have this code that I want to insert for my own variable but I have no idea how. This is what I want to insert:Code: <?php echo $my_twitter_username; ?>Into this code:Code:
Simple PHP/Java Help..
Hi,I'm trying to build a little program to do with calculating postage. Unfortunately i haven't got a very good idea of how to use PHP, Java, or any other languages - apart from CSS and HTML -_-. If
Hi, explode and strstr.
Hi, I seem to be confused about the strstr function, eg. i have a string like:"a.b.c.d.e.f""a.b.c.d.e"I always want it to split at the second "." from the end, so
What's best way to get a user's Word doc converted to simple html and images?
Hi all,I was just wondering if anybody has any experience of this.Basically, I'm building a site for a guy and he keeps throwing tonnes of content my way, all Word docs with tables, images, etc.The
Array help
Hello i got this code to fetch data from database but it is not working it displays7ArrayArrayArrayArrayArrayArrayCode: if (isset($_POST['showrecord'])){ $query='SELECT * FROM artus_test';
Coefficient of a Restitution Hints
Hello. I was wondering if anyone can give me hints on how to write this program...The coefficient of a restitution of a ball, a number between 0 and 1, specifiies how much energy is conserved when a
ctype() validation - allowing illegal characters
Hello,I use ctype() to filter and validate a user form. However, I am trying to allow certain characters.Example:Code: [Select]//Validate Copay $allow = array('$', '.'); if (!empty($copay)
Thread in PHP
Thread in PHPSome basic use and basic code for thread in phpThis is my question?