Jump to content

Freedom-n-Democrazy

Members
  • Posts

    295
  • Joined

  • Last visited

    Never

Posts posted by Freedom-n-Democrazy

  1. Lets say I have a MySQL value of 4... and I have a HTML INPUT field.. Is there a way to make it so that if a client tries to submit a value higher than 4, then they will be returned a message? Something like:

     

    <SCRIPT type="text/javascript">
    function validateForm() {
    	if (document.forms["form"]["quantity"].value== (+$row['quantity']) {
    		alert ("Cannot submit because the quantity specified is not available.");
    		return false;
    	}
    }
    </SCRIPT>
    <INPUT name="quantity">
    

  2. Whats wrong with this arithmetic code?

     

    $sizestotal = $content['sizes'] * $row['price'];
    $sizeltotal = $content['sizem'] * $row['price'];
    $sizeltotal = $content['sizel'] * $row['price'];
    $sizeltotal = $content['sizexl'] * $row['price'];
    $idtotal = $sizestotal + $sizemtotal + $sizeltotal + $sizexltotal;
    $total += $idtotal;
    

  3. Yep, thats the exact code I used from the start. I suspect the error is else where:

     

     

    <?php
    	session_start();
    if (empty($_SESSION['cart']['content'])) {
    	echo '<DIV class="nocart">No product in cart.</DIV>';
    }
    else {
    	echo '	<DIV class="cartcontent">';
    		$link = mysql_connect('localhost', 'testusr', 'testpw');
    		mysql_select_db('testdb', $link);
    		foreach ($_SESSION['cart']['content'] as $content) {
    		$query = "select * from products where id='{$content['id']}'"; $result = mysql_query($query); $row = mysql_fetch_array($result);
    		echo '
    			<DIV class="cartproduct">
    				<DIV class="productdescriptor">
    					'.$row['id'].'
    					<BR>
    					<IMG alt="" class="thumbnail" src="../products/'.$row['fordir'].'/'.$row['categorydir'].'/'.$row['id'].'/thumbnail.png">
    				</DIV>
    				<DIV class="cartproductdata">
    		';
    	';
    					if ($content['sizes'] == 0) {goto sizem;} else {echo "<B>Small:</B> ".$content['sizes'];}
    					echo "<BR>";
    					sizem:
    					if ($content['sizem'] == 0) {goto sizel;} else {echo "<B>Medium:</B> ".$content['sizem'];}
    					echo "<BR>";
    					sizel:
    					if ($content['sizel'] == 0) {goto sizexl;} else {echo "<B>Large:</B> ".$content['sizel'];}
    					echo "<BR>";
    					sizexl:
    					if ($content['sizexl'] == 0) {goto endsizes;} else {echo "<B>Extra large:</B> ".$content['sizexl'];}
    					echo "<BR>";
    					endsizes:
    					echo '	<BR>
    						<BR>
    						<B>Unit price:</B> $'.$row[price].' AUD
    						<BR>
    						<BR>
    						<INPUT type="submit" value="REMOVE FROM CART">
    				</DIV>
    			</DIV>
    		';
    		$sizestotal = $content['sizes'] * $row['price'];
    		$sizeltotal = $content['sizel'] * $row['price'];
    		$idtotal = $sizestotal + $sizeltotal;
    		$total = $idtotal;
    	}
    	echo "	</DIV>";
    	mysql_query ($query);
    	mysql_close($link);
    	echo '
    		<DIV class="totalandproceed">
    			Total: $'.$total.'
    			<BR>
    			<INPUT type="submit" value="PROCEED TO PAYMENT">
    		</DIV>
    	';
    }
    
    ?>
    

  4. What is a T_STRING? google.com cannot find anything about it in the PHP manual.

     

    ... and, why am I getting "unexpected T_STRING" for this line?

    if ($content['sizes'] == 0) {goto sizem;} else {echo "<B>Small:</B> '.$content['sizes'].'";}
    

  5. There is. I just re-wrote my code:

     

    if ($_POST['size'] == "Small") {
    if (isset($_SESSION['cart']['content'][$_POST[id]])) {
    	$_SESSION['cart']['content'][$_POST[id]]['sizes'] += $_POST['quantity'];
    } else {
    	$_SESSION['cart']['content'][$_POST[id]] = array ('id' => $_POST['id'], 'sizes' => $_POST['quantity']);
    }
    } elseif ($_POST['size'] == "Large") {
    if (isset($_SESSION['cart']['content'][$_POST[id]])) {
    	$_SESSION['cart']['content'][$_POST[id]]['sizel'] += $_POST['quantity'];
    } else {
    	$_SESSION['cart']['content'][$_POST[id]] = array ('id' => $_POST['id'], 'sizel' => $_POST['quantity']);
    }
    }
    

  6. Is there a shorter way to achieve this in a single foreach()?

     

    foreach ($_SESSION['cart']['content']['sizes'] as $content);
    foreach ($_SESSION['cart']['content']['sizem'] as $content);
    foreach ($_SESSION['cart']['content']['sizel'] as $content);
    

     

    I am thinking something like:

    foreach ($_SESSION['cart']['content']['sizes'] && $_SESSION['cart']['content']['sizem'] && $_SESSION['cart']['content']['sizel'] as $content);
    

    or

    foreach ($_SESSION['cart']['content'] = ['sizes'] || ['sizem'] || ['sizel'] as $content);
    

  7. Never mind. I have re-wrote the way entities are stored in the session. They are now stored as:

    $_SESSION['cart']['content'][$_POST[id]][$_POST[size]] = array ('quantity' => $_POST['quantity'])

     

    opposed to:

    $_SESSION['cart']['content'][] = array ('id' => $_POST['id'], 'size' => $_POST['size'], 'quantity' => $_POST['quantity'])

     

    EDIT: Well, this is flawed. But I will figure it out.

  8. Unfortunately, I spoke too soon. Now another problem has developed.

     

    If I add an entity with a quantity of 1, and then add the same entity with a quantity of 1, I get a single entity with a quantity of 2, however,

    If I add an entity with a quantity of 1, and then add the same entity with a quantity of 3, I get two entities - entity A/quantity-1 & entity A/quantity-3.

     

    Why is this happening?

     

    http://i52.tinypic.com/30bgtww.png

     

    <?php
    session_start();
    if (isset($_SESSION['cart']['content'][$_POST['id']])) {
    	$_SESSION['cart']['content'][$_POST[id]]['quantity'] += $_POST['quantity'];
    } else {
    	$_SESSION['cart']['content'][] = array ('id' => $_POST['id'], 'size' => $_POST['size'], 'quantity' => $_POST['quantity']);
    }
    echo '<DIV class="result">Added to cart.</DIV>';
    echo $_SESSION['cart']['content'][$_POST['id']]['quantity'];
    ?>
    

×
×
  • 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.