.chester Posted May 6, 2012 Share Posted May 6, 2012 Hello, I'm working on an online bookstore and I'm having some problems with the shopping cart section. On the book page I have the following code, which is supposed to gather information like book title, author and price and send it to the shopping cart: <form action="cos.php?actiune=adauga" method="post"> <input type="hidden" name="id_carte" value="<?=$id_carte?>"> <input type="hidden" name="titlu" value="<?=$rowCarte['titlu']?>"> <input type="hidden" name="autor" value="<?=$rowCarte['nume_autor']?>"> <input type="hidden" name="pret" value="<?=$rowCarte['pret']?>"> <input type="submit" value="Cumpara acum!"> </form> Cart.php looks like this: <?php session_start(); include("conectare.php"); include("pagetop.php"); include("meniu.php"); $actiune=$_GET['actiune']; if(isset($_GET['actiune']) && $_GET['actiune']=="adauga") { $_SESSION['id_carte'][]=$_POST['id_carte']; $_SESSION['nr_buc'][]=1; $_SESSION['pret'][]=$_POST['pret']; $_SESSION['titlu'][]=$_POST['titlu']; $_SESSION['nume_autor'][]=$_POST['nume_autor']; } if(isset($_GET['actiune']) && $_GET['actiune']=="modifica") { for($i=0; $i<count($_SESSION['id_carte']); $i++) { $_SESSION['nr_buc'][$i]=$_POST['noulNrBuc'][$i]; } } ?> <td align="top"> <h1>Cosul de cumparaturi</h1> <form action="cos.php?actiune=modifica" method="post"> <table border="1" cellspacing="0" cellpadding="4"> <tr bgcolor="#F9F1E7"> <td><b>Nr. Buc</b></td> <td><b>Carte</b></td> <td><b>Pret</b></td> <td><b>Total</b></td> </tr> <?php for($i=0; $i<count($_SESSION['id_carte']); $i++) { if($_SESSION['nr_buc'][$i] !=0) { print '<tr><td><input type="text" name="noulNrBuc['.$i.']" size="1" value="'.$_SESSION['nr_buc'][$i].'"></td> <td>'.$_SESSION['titlu'][$i].' de '.$_SESSION['nume_autor'][$i].' </td> <td align="right">'.$_SESSION['pret'][$i].' lei </td> <td align="right">'.($_SESSION['pret'][$i] * $_SESSION['nr_buc'][$i]).' lei </td> </tr>'; $totalGeneral=$totalGeneral + ($_SESSION['pret'][$i] * $_SESSION['nr_buc'][$i]); } } print '<tr><td align="right" colspan="3"> Total in cos </td><td align="right">'.$totalGeneral.' lei </td></tr>'; ?> </table> <input type="submit" value="Modifica"><br><br> Introduceti 0 pentru cartile ce doriti sa le scoateti din cos! <h1>Continuare</h1> <table> <tr> <td width="200" align="center"><img src="cos.jpg"><a href="index1.php">Continua cumparaturile</a></td> <td width="200" align="center"><img src="casa.jpg"><a href="casa.php">Mergi la casa</a></td> </tr> </table> </td> <?php include("page_bottom.php"); ?> My problem is every time I add a book to the cart, nothing is updated except for the quantity, so I have no author, title or price info, like so: I'm just starting php coding and I can't figure out what's going on. Anyone willing to lend a helping hand? Quote Link to comment https://forums.phpfreaks.com/topic/262155-shopping-cart-display-problem/ Share on other sites More sharing options...
WatsonN Posted May 7, 2012 Share Posted May 7, 2012 I looked over your code and your form is using POST but all your if statements are wanting a GET, this may be from one of your includes, but that may be part of why it isn't displaying what you want. Quote Link to comment https://forums.phpfreaks.com/topic/262155-shopping-cart-display-problem/#findComment-1343628 Share on other sites More sharing options...
.chester Posted May 7, 2012 Author Share Posted May 7, 2012 I did a bit of troubleshooting and came up with a few concerning facts: 1. I've checked the source for the "Add to cart" button and it seems it doesn't pass any info except id_carte, as evidenced by the empty values: <form action="cos.php?actiune=adauga" method="post"> <input type="hidden" name="id_carte" value="6"> <input type="hidden" name="titlu" value=""> <input type="hidden" name="autor" value=""> <input type="hidden" name="pret" value=""> <input type="submit" value="Cumpara acum!"> </form> 2. I also used var_dump and it returns the following, which I guess makes sense: array(5) { ["id_carte"]=> array(1) { [0]=> string(1) "3" } ["nr_buc"]=> array(1) { [0]=> int(1) } ["pret"]=> array(1) { [0]=> string(0) "" } ["titlu"]=> array(1) { [0]=> string(0) "" } ["nume_autor"]=> array(1) { [0]=> NULL } } So I guess the "Add to cart" button isn't sending the required info, which is why there's nothing to display in the shopping cart, except quantity and id_carte. Now what? Quote Link to comment https://forums.phpfreaks.com/topic/262155-shopping-cart-display-problem/#findComment-1343657 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.