Page 1 of 1

add to cart problem

Posted: Sun May 15, 2005 4:32 pm
by Think Pink
hello,
i have a little problem in a "add to basket" that i made.
if i choose in 1.php some books and than i submit the form, is all ok, but after if i want to see the basket, it does not show me any books in it.
need advice pls?

1.php
...
<input type="checkbox" name="id[]" value="<?=$id;?>">
...

2.php

Code: Select all

<?php
session_start();

$n=count($_POST['id']);
?>

<table align="left" cellspacing="2" cellpadding="2" border="1">
<tr>
<td><b>id</b></td>
</tr>

<?php
for($i=0;$i<$n;$i++) { 
$_SESSION['id'][$i]=$_POST['id'][$i];
?>

<tr>
<td><?=$_SESSION['id'][$i];?></td>
</tr>

<?php
} // end for
?>
</table>
how could i display the id of books i selected in 2.php?

Posted: Sun May 15, 2005 6:56 pm
by josh-j
Have you tried printing out the contents of $_POST? Insert this just before $n=count($_POST['id']);

Code: Select all

echo '<pre>';
var_dump($_POST);
echo '</pre>';
The problem may be occurring somewhere else in the code, so I find this a helpful method to make sure the data is doing what it ought to.

For example, I've had problems in the past with code like

Code: Select all

value="<?=$id;?>"
and it seems some servers won't allow this shorthand, but insist on code like

Code: Select all

value="<?php echo $id; ?>"
Anyway let me know how it goes.