Hi. I am attempting to build a very simple shopping cart using php for an assignment. I am displaying the images and relevant details for the product from a MYSQL database. I want the customer to be able to select as many products as they wish, and then click the Purchase button which will take them to shop_cart.php. This page will display the products they have chosen. I cannot work out how to display the chosen products in shop_cart.php. I have included the functions for first page - shop_didge() - and then the display - page shop_cart(). Where I want the id to display the id of sb1253 I get a:3:{i:0;s:6:"sb1253";} and $timber displays N; whereas it should be Stringy Bark. Appreciate any help. <?php } function shop_didge(){ ?> <form action="shop_cart.php" method="post"> <table class='table9' align='center'> <?php // Get all the data from the "products" table $result = mysql_query("select * from products where SOLD=''") or die(mysql_error()); // keeps getting the relevant info until there are no more to get while($col = mysql_fetch_array( $result )) { echo "<tr><td colspan='2'><strong>Didge ID: "; echo $col['productid']; echo "</strong></td></tr><tr><td colspan='2'><img class='image' src='images/"; echo $col['longimage']; echo "' />"; echo "</td><tr><td><img class='image' src='images/"; echo $col['mouthimage']; echo "' /></td><td rowspan='2'>"; echo "<table class='table10'>"; echo "<tr><td>Timber:</td>"; echo "<td>"; echo $col['timber']; echo "</td></tr><tr>"; echo "<td>Length:</td><td>"; echo $col['length']; echo "cm</td></tr><tr>"; echo "<td>Mouth:</td><td>"; echo $col['mouth']; echo "cm</td></tr><tr>"; echo "<td>End:</td><td>"; echo $col['end']; echo "cm</td></tr><tr>"; echo "<td>Weight:</td><td>"; echo $col['weight']; echo "kg</td></tr><tr>"; echo "<td>Key:</td><td>#"; echo $col['key']; echo "</td></tr><tr>"; echo "<td>Soundfile:</td><td><a href='"; echo $col['soundfile']; echo "'>"; echo $col['soundfile']; echo "</a></td></tr><tr>"; echo "<td>Price:</td><td>$"; echo $col['price']; echo "</td></tr><tr>"; echo "<td>Purhase:</td>"; //edit if wrong echo "<td><input name='id[]'"; echo $col['productid']; echo "' type='checkbox' value='"; echo $col['productid']; echo "'></td>"; echo "</tr></table>"; echo "</td></tr>"; echo "<tr><td><img class='image' src='images/"; echo $col['endimage']; echo "' /></td></tr>"; echo "<tr><td colspan='2'><hr /></td></tr>"; echo "$productid"; } ?> <tr> <td colspan="2" align="right"><input type="submit" name="purchase" value="Purchase" /></td> </tr> </table> </form> //Display page <?php } function shop_cart(){ ?> <?php $id=serialize($_POST['id']); $timber=serialize($_POST['timber']); ?> <table class="table9" align="center"> <tr> <td>Product ID</td> <td>Description</td> <td>Price</td> </tr> <?php echo '<tr><td>'; echo $id; echo '</td></tr><tr><td>'; echo $timber; echo '</td></tr>'; ?> </table>
$id=serialize($_POST['id']); $timber=serialize($_POST['timber']); Code (markup): You are serializing the data so when u want to view it u need to unserialize it However if the page is automatically going to the show_cart page and u want to display them their their is no need to serialize it just echo it $id=$_POST['id'] Code (markup):
Thanx for your response Big 'G'. I did do that, but then it would only display the word Array. I didn't think using serialize was correct, but so far it is the only thing that displays something close to what I want. Any other suggestions?
if on the follow up page u type this echo "<pre>"; print_r($_POST); echo "</pre>"; Code (markup): You will get a nice formated layout of the array, use $_GET is using the get method. Then just reference your vars $myvar =$_POST['wood'];