Jump to content

Quantity Crazy


Snatch

Recommended Posts

Good Evening Gents!

 

I'm having problems. When I add certain quantitys of products to my shopping basket they appear present and correct.

 

However, when I get to the last stage of my checkout all the quantitys of products in the basket are changed to the same.

 

eg:

 

2 x test

4 x test2

 

becomes:

 

4 x test

4 x test2

 

I've spent all day playing with it to no avail. It's frustraiting because once this is sorted my site should be finished - touch wood! Any suggestions would be gladfully recieved!

 

checkout2.php The user is asked to confirm products here, the quantitys appear correct.

 

 

     <?php
       $sessid = session_id();
       $query = "SELECT * FROM baskettemp WHERE sess = '$sessid'";
      $results = mysql_query($query)
          or die (mysql_query());
           while ($row = mysql_fetch_array($results)) {
               extract ($row);
               $prod = "SELECT * FROM products WHERE
                    id = '$prodnum'";
               $prod2 = mysql_query($prod);
               $prod3 = mysql_fetch_array($prod2);
               extract ($prod3);
               echo "<td>";
               echo $quan;
               echo "</td>";
               echo "<td>";
               echo $type;
               echo "</td>";
		   echo "<td>";
               echo $name;
               echo "</td>";
               echo "<td align='right'>";
               echo $price;
               echo "</td>";
               echo "<td align='right'>";
          //get extended price
               $extprice = $price * $quan;
               echo number_format($extprice, 2);
               echo "</td>";
               echo "<td>";
		   echo "</td>";
               echo "<td>";
               echo "<a href='basket.php'>Make Changes to basket</a>";
               echo "</td>";
               echo "</tr>";
          //add extended price to total
               $total = $extprice + $total;

               }
?>

checkout3.php This is the receipt.  The quantitys appear all the same...

 

 

<?php
//3) Insert Info into orderdet
     //find the correct basket information being temporarily stored
     $query = "SELECT * from baskettemp WHERE sess='$sessid'";
     $results = mysql_query($query)
          or (mysql_error());
//put the data into the database one row at a time
     while ($row = mysql_fetch_array($results)) {
               extract ($row);
               $query4 = "INSERT INTO orderdet (ordernum, qty, prodnum)
                    VALUES (
                    '$orderid',
                    '$quan',
                    '$prodnum')";
               $insert4 = mysql_query($query4)
                    or (mysql_error());
     }
?>

 

<?php 
$query = "SELECT * from orderdet WHERE ordernum = '$orderid'";
     $results = mysql_query($query)
          or die (mysql_query());
          while ($row = mysql_fetch_array($results)) {
               extract ($row);
               $prod = "SELECT * FROM products
                        WHERE id = '$prodnum'";
               $prod2 = mysql_query($prod);
               $prod3 = mysql_fetch_array($prod2);
               extract ($prod3);
 		   echo "<tr>";
		   echo "<td>";
		   echo $quan;
		   echo "</td>"; 
		   echo "<td>";
		   echo $type;
		   echo "</td>"; 
               echo "<td>";
               echo $name;
               echo "</td>";
		   echo "<td>";
		   echo $quote_no;
		   echo "</td>";
		   echo "<td>"; 
               echo $price;
               echo "</td>";
               echo "<td>";
          //get extended price
                $extprice = $price * $quan;
               echo number_format($extprice, 2);
               echo "</td>";
		   }
?>

 

 

Link to comment
Share on other sites

U must call session_start() before using session_id(). Anyway even that works without session_start(), in checkout3.php u are making the query WHERE sess='$sessId' but i can see $sessId being initialized only in the first code. The code looks ok from my quick look, but if those arent the problems ill take another patient look. Also one thing, u dont have to use extract all the time. In the following code:

extract ($row);
$prod = "SELECT * FROM products WHERE id = '$prodnum'";

 

instead u can just use:

$prod = "SELECT * FROM products WHERE id = '{$row['prodnum']}'";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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