Jump to content

[SOLVED] php shopping cart giving me grief :@(


capstin

Recommended Posts

Hello fellow php'ers...  I am having a little trouble in my design of a shopping cart for a website i am putting together.  It has had me baffled for weeks now.  Below is the demo link i have been using for testing my components.  I basically have an html page splite into 3 sections...  One for a search, two for search results and three for my shopping cart.  If (when the page loads) i add/remove a song to/from my shopping cart it works fine.  But, if i do a new search and add a new song my cart goes way wonky!  Have a bash at it using the link below... Any help would be most welcome.  It is driving me insane!  I just can't work out why executing the same set of code would produce different results.

 

http://www.capstinpole.co.uk/picknclick-demo/nutsnbolts/switch.php (select the bottom option All.hmtl...) - The switch.php page resets my $_SESSION arrays to default.

 

If you need anymore info on this please let me know...

A massive selection box in the post for the one who solves the mystery.

 

Please note: I am fairly new to all this programming so no laughing!

 

Best wishes!

 

Michael

 

 

 

 

 

 

Link to comment
Share on other sites

no probs... 

 

cart.php receives the following variables...

 

<form action="cart.php" method="post" name="CartGoodies" target="FooterFrame">

        <input name="item_no" type="hidden" value="<? echo $item_no; ?>">

        <input name="artist" type="hidden" value="<? echo $artist; ?>">

        <input name="song" type="hidden" value="<? echo $song; ?>">

        <input name="Submit" type="submit" class="style10" value="Add to cart" />

        <input name="manufact" type="hidden" value="<? echo $manufact; ?>">

        <input name="cost" type="hidden" value="<? echo $cost; ?>">

      </form> 

 

 

-------------------------------------------

cart.php script...

 

<?

$_SESSION['total'] = 0.00; // Accumulates Cost

$count = $_SESSION['rec_count'];

$dup_chk = $_POST['item_no'];

 

//

if (!empty($_POST['artist'])) {

 

for ($c = 1; $c < $count; $c++) {

 

if ($_SESSION['item_no'][$c] == $dup_chk) {

 

// checking for duplicate cart entries...                                       $_SESSION['qty'][$c] +=1;

$_SESSION['amount_adj'][$c] = (float) $_POST['cost'] * $_SESSION['qty'][$c];

$_SESSION['artist'][$count] = "";

$c = $count;

 

}

 

else {

 

//no duplicates found... Add contents to session var's...                           $_SESSION['item_no'][$count] = $_POST['item_no'];

$_SESSION['artist'][$count] = $_POST['artist'];

$_SESSION['song'][$count] = $_POST['song'];

$_SESSION['manufact'][$count] = $_POST['manufact'];

$_SESSION['qty'][$count] = 1;

$_SESSION['amount_adj'][$count] = $_POST['cost'];

}

}

}

 

if ($count == 1){

 

//Check for first run... * * * * * * * * * * * * * * * *

$_SESSION['item_no'][$count] = $_POST['item_no'];

$_SESSION['artist'][$count] = $_POST['artist'];

$_SESSION['song'][$count] = $_POST['song'];

$_SESSION['manufact'][$count] = $_POST['manufact'];

$_SESSION['qty'][$count] = 1;

$_SESSION['amount_adj'][$count] = $_POST['cost'];

 

}

 

 

//Remove Item ... $remove is passed through the browser - <a href="cart.php?remove=<? echo $i+1; ?>

                          if (!empty($remove)){

 

//variable wipeouts

unset($_SESSION['item_no'][$remove]);

unset($_SESSION['artist'][$remove]);

unset($_SESSION['song'][$remove]);

unset($_SESSION['manufact'][$remove]);

unset($_SESSION['qty'][$remove]);

unset($_SESSION['amount_adj'][$remove]);

}

 

// Display Cart contents >>> 

$i=0;

while ($i < $count) {

 

If (empty($_SESSION['artist'][$i+1])) {

$i++;

$msg5 = "Artist $i is empty - statements executed.";

}

 

else {

               // draw html row

 

Hope this helps...

 

Thanks for support!

 

Michael

 

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.