Jump to content

Shopping cart display problem


.chester

Recommended Posts

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:

 

69n7mo.png

 

I'm just starting php coding and I can't figure out what's going on. Anyone willing to lend a helping hand?  :shy:

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

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.