Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 24th, 2006, 10:20 AM
Registered User
 
Join Date: May 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Shopping Cart Script in Chapter 15

I have fully developed the shopping cart script in chapter 15 of the beginning php book. I am having problems however when running it with the extract function.

Below is a segment of my script, can anyone tell me why this isnt working? when I run the script I do not get any product information into the cart, it will add but no details shown of the product!

<HEAD>
<TITLE> Shopping Cart </TITLE>
</HEAD>
<BODY>
<div align ="center">
You currently have';

$sessid = session_id();
$query = "SELECT * FROM CSFC_CARTTEMP WHERE carttemp_sess ='$sessid'";
$results = mysql_query($query);
$rows = mysql_num_rows($results);
echo $rows;
?>

product(s) in your cart.<br>

<table border="1" align="center" cellpadding="5">
<tr>
   <td>Quantity</td>
   <td>Item image</td>
   <td>Item Name</td>
   <td>Price Each</td>
   <td>Extended price</td>
   <td></td>
   <td></td>

<?php
$total = 0;
while ($row = mysql_fetch_array($results)) {
echo "<tr>";
extract($row);
$prod = "SELECT * FROM CSFCPRODUCTS " . "WHERE products_prodnum='$carttemp_prodnum'";
$prod2 = mysql_query($prod);
$prod3 = mysql_fetch_array($prod2);
extract($prod3);
echo "<td>
<form method=\"POST\" action=\"modcart.php?action=change\">
<input type=\"hidden\" name\"modified_hidden\" value=\"$carttemp_hidden\">
<input type=\"text\" name=\"modified_quan\" size=\"2\" value=\"$carttemp_quan\">";
echo "</td>";


Thanks in advance,
Barry

 
Old May 30th, 2006, 01:05 PM
Registered User
 
Join Date: May 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Just from glancing...maybe it's just a syntax error or spelling error.

Do all your tables have uniformity? Should maybe CSFCPRODUCTS be CFSC_PRODUCTS? Also...why is the syntax on this line the way it is?

$prod = "SELECT * FROM CSFCPRODUCTS " . "WHERE products_prodnum='$carttemp_prodnum'";

Is there a specific reason you used the appending . on there?
Maybe try
$prod = "SELECT * FROM CSFCPRODUCTS WHERE products_prodnum = '$carttemp_prodnum'";

These are just suggestings I couldn't see anything else different from what I've been doing...I'm actually having a different problem on the same script (populating the "ordermain" table) but I thought maybe this might help ya

Mike

 
Old June 2nd, 2006, 04:14 AM
Registered User
 
Join Date: May 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, I have tried adding that instead but I keep getting the same error message: -

Warning: extract() expects first argument to be an array in /usr/local/httpd/htdocs/hnd6/cart.php on line 43

Line 43 is this area

<?php
$total = 0;
while ($row = mysql_fetch_array($results)) {
echo "<tr>";
extract($row);
$prod = "SELECT * FROM CSFCPRODUCTS WHERE products_prodnum = '$carttemp_prodnum'";
$prod2 = mysql_query($prod);
$prod3 = mysql_fetch_array($prod2);
extract($prod3); //Line 43

 
Old June 4th, 2006, 10:06 PM
Registered User
 
Join Date: May 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Geeze I dunno man from comparing your code to mine (and mine works!) it looks exactly the same...the only thing I can think of is its not pulling the data from $prod correctly, so its not finding the CFSPRODUCTS table and grabbing the data from it???

Have you checked your tables after you have run the script to see if they've ALL been populated correctly????

I use SQLyog (FREE Version) and it has helped me TREMENDOUSLY with real time troubleshooting of my tables and stuff as I'm learning PHP:

http://www.webyog.com/sqlyog/download.html

I wish I could be more help but I am fairly new too (and it doesn't look like a lot of people are responding to the posts, you'd think they'd have an expert on the book monitor this stuff!) so I'm at a los...good luck man.

Mike

 
Old June 7th, 2006, 08:21 AM
Registered User
 
Join Date: May 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Cheers mate,
that link has helped me a lot! Its actually working now, there was a problem with the arrays but is sorted now.
Thanks for replying






Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 13 Shopping Cart michaelcode BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 9 January 25th, 2010 03:50 AM
Chapter 13: shopping cart problem mysecondlove BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 0 April 9th, 2008 06:48 PM
Chapter 13 Shopping Cart disappears after login bwinklesky BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 1 June 14th, 2007 12:34 PM
chapter 15 cart.php pink BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 July 18th, 2005 05:45 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.