Wrox Programmer Forums
|
BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6
This is the forum to discuss the Wrox book Beginning PHP, Apache, MySQLWeb Development by Michael K. Glass, Yann Le Scouarnec, Elizabeth Naramore, Gary Mailer, Jeremy Stolz, Jason Gerner; ISBN: 9780764557446
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 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 January 4th, 2005, 11:50 AM
Registered User
 
Join Date: Jul 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Array error in checkout3 file

When I run the shopping cart everything works fine until I do the final check out on the checkout3 page. The email confirmation shows two errors.

I get this error message 11 time.
Warning: extract(): First argument should be an array in /home/global01/public_html/storefront/checkout3.php on line 177

Then further down the page I get this error 11 times:

Warning: extract(): First argument should be an array in /home/global01/public_html/storefront/checkout3.php on line 286

And here is the purchase recap that is printed out.

12 Accent Color Frame AST 6.25 75.00
12 Accent Color Frame AST 6.25 75.00
12 Accent Color Frame AST 6.25 75.00
12 Accent Color Frame AST 6.25 75.00
12 Accent Color Frame AST 6.25 75.00
12 Accent Color Frame AST 6.25 75.00
12 Aruba 4.00 48.00
12 Accent Color Frame AST 6.25 75.00
12 Accent Color Frame AST 6.25 75.00
12 Accent Color Frame AST 6.25 75.00
12 Accent Color Frame AST 6.25 75.00
Your total before shipping is: 75.00
Shipping Costs: 18.75
Your final total is: 93.75


And finally here is the code referenced in the error messages line 168 - 193:

 $query = "SELECT * from orderdet WHERE ordernum = '$orderid'";
     $results = mysql_query($query)
          or die (mysql_query());
          while ($row = mysql_fetch_array($results)) {
               extract ($row);
               $prod = "SELECT * FROM products
                        WHERE prodNum = '$prodNum'";
               $prod2 = mysql_query($prod);
               $prod3 = mysql_fetch_array($prod2);
               extract ($prod3);
               $message .= "<td>";
               $message .= $quan;
               $message .= "</td>";
               $message .="<td>";
               $message .= $name_frame;
               $message .= "</td>";
               $message .= "<td align='right'>";
               $message .= $costPrice;
               $message .= "</td>";
               $message .= "<td align='right'>";
          //get extended price
               $extprice = number_format($costPrice * $quan, 2);
               $message .= $extprice;
               $message .= "</td>";
               $message .= "</tr>";
               }

And line 277 - 302:

  <?php
      $query = "SELECT * from orderdet WHERE ordernum = '$orderid'";
     $results = mysql_query($query)
          or die (mysql_query());
          while ($row = mysql_fetch_array($results)) {
               extract ($row);
               $prod = "SELECT * FROM products WHERE prodNum = '$prodNum'";
               $prod2 = mysql_query($prod);
               $prod3 = mysql_fetch_array($prod2);
               extract ($prod3);
               echo "<td>";
               echo $quan;
               echo "</td>";
               echo "<td>";
               echo $name_frame;
               echo "</td>";
               echo "<td align='right'>";
               echo $costPrice;
               echo "</td>";
               echo "<td align='right'>";
          //get extended price
               $extprice = number_format($costPrice * $quan, 2);
               echo $extprice;
               echo "</td>";
               echo "</tr>";
               }

Any help would be greatly appreciated.
You can check it out here:
http://www.gvtest.us/storefront/cbashop.php

 
Old January 4th, 2005, 03:35 PM
Authorized User
 
Join Date: Dec 2004
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, the error is basically telling you that extract() cannot do its job because the supplied array is not an array. So both lines are trying to extract the variables from the array $prod3. Well, if $prod3 is not an array then you'll get the error. Thus, what it's telling me is that your SQL query is most likely turning up empty. Are you sure you have this line written correctly?

Code:
$prod = "SELECT * FROM products
       WHERE prodNum = '$prodNum'";


Is the name of your column truely prodNum with a capital 'N' and not prodnum? And how about your variable that you're trying to match, $prodNum? I ask the same thing? Is it supposed to have a capital 'N'? Last, if $prodNum is spelled correct, yet is not instantiated earlier in the script, thus being empty, then the query fails and you'll get the error. So make sure $prodNum has been instantiated. This is done earlier in the script from the query to your carttemp table in step 3:

Code:
//3) Insert Info into orderdet
     //find the correct cart information being temporarily stored
     $query = "SELECT * from carttemp WHERE sess='$sessid'";
     $results = mysql_query($query)
          or (mysql_error());

     //put the data into the database one row at a time
     while ($row = mysql_fetch_array($results)) {
          extract ($row);


Well, the code continues, but the last line of code above is where your $prodNum variable is instantiated. You need to check your carttemp table and see what the name of the column really is. If it's prodnum instead of prodNum, then that's where your problem lies.

Alright, I hope it helps.
 
Old January 4th, 2005, 03:57 PM
Registered User
 
Join Date: Jul 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here is the complete code for the checkout3 file.

<?php
session_id();
session_start();
//connect to the database - either include a connection variable file or
//type the following lines:
$connect = mysql_connect("localhost", "global01_jerry", "g5x7w345")or
die ("There seems to be a problem with the database. please check back late. To inform us of the problem please go to the contact page and click on support@globalvision.us.");
mysql_select_db ("global01_GVis01");
//Let's make the variables easy to access in our queries
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$firstname = $_POST['firstname'];
$add1 = $_POST['add1'];
$add2 = $_POST['add2'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$phone = $_POST['phone'];
$fax = $_POST['fax'];
$email = $_POST['email'];
$shipfirst = $_POST['shipfirst'];
$shiplast = $_POST['shiplast'];
$shipadd1 = $_POST['shipadd1'];
$shipadd2 = $_POST['shipadd2'];
$shipcity = $_POST['shipcity'];
$shipstate = $_POST['shipstate'];
$shipzip = $_POST['shipzip'];
$shipstate = $_POST['shipstate'];
$shipphone = $_POST['shipphone'];
$shipemail = $_POST['shipemail'];
$total = $_POST['total'];
$sessid = session_id();
$today = date("Y-m-d");
//1) Assign Customer Number to new Customer, or find existing customer number
     $query = "SELECT * FROM customers WHERE
          (firstname = '$firstname' AND
          lastname = '$lastname' AND
          add1 = '$add1' AND
          add2 = '$add2' AND
          city = '$city')";
     $results = mysql_query($query)
          or (mysql_error());
     $rows = mysql_num_rows($results);

     if ($rows < 1) {
          //assign new custnum
          $query2 = "INSERT INTO customers (
          firstname, lastname, add1, add2, city, state, zip, phone, fax, email)
           VALUES (
          '$firstname',
          '$lastname',
          '$add1',
          '$add2',
          '$city',
          '$state',
          '$zip',
          '$phone',
          '$fax',
          '$email')";
          $insert = mysql_query($query2)
               or (mysql_error());
          $custid = mysql_insert_id();
     }
     //If custid exists, we want to make it equal to custnum
     if($custid) $custnum = $custid;
//2) Insert Info into ordermain
     //determine shipping costs based on order total (25% of total)
     $shipping = $total * 0.25;

     $query3 = "INSERT INTO ordermain (orderdate, custnum, subtotal,
                shipping, shipfirst, shiplast, shipadd1, shipadd2,
               shipcity, shipstate, shipzip, shipphone, shipemail)
          VALUES (
          '$today',
          '$custnum',
          '$total',
          '$shipping'
          '$shipfirst',
          '$shiplast',
          '$shipadd1',
          '$shipadd2',
          '$shipcity',
          '$shipstate',
          '$shipzip',
          '$shipphone',
          '$shipemail')";
     $insert2 = mysql_query($query3)
          or (mysql_error());
     $orderid = mysql_insert_id();

//3) Insert Info into orderdet
     //find the correct cart information being temporarily stored
     $query = "SELECT * from carttemp WHERE sess='$sessid'";
     $results = mysql_query($query)
          or (mysql_error());

     //put the data into the database one row at a time
     while ($row = mysql_fetch_array($results)) {
               extract ($row);
               $query4 = "INSERT INTO orderdet (ordernum, qty, prodNum)
                    VALUES (
                    '$orderid',
                    '$quan',
                    '$prodNum')";
               $insert4 = mysql_query($query4)
                    or (mysql_error());
     }

//4)delete from temporary table
     $query="DELETE FROM carttemp WHERE sess='$sessid'";
     $delete = mysql_query($query);


//5)email confirmations to us and to the customer
/* recipients */
$to = "<" . $email .">";

/* subject */
$subject = "Order Confirmation";

/* message */
     /* top of message */
     $message = "
       <html>
       <head>
       <title>Order Confirmation</title>
       </head>
       <body>
     Here is a recap of your order:<br><br>
     Order date:";
 $message .= $today;
 $message .= "
     <br>
      Order Number: ";
 $message .= $orderid;
 $message .= "
     <table width='50%' border='0'>
      <tr>
        <td>
         <p>Bill to:<br>";
 $message .= $firstname;
 $message .= " ";
 $message .= $lastname;
 $message .= "<br>";
 $message .= $add1;
 $message .= "<br>";
 if ($add2) $message .= $add2 . "<br>";
 $message .= $city . ", " . $state . " " . $zip;
 $message .= "</p></td>
    <td>
      <p>Ship to:<br>";
 $message .= $shipfirst . " " . $shiplast;
 $message .= "<br>";
 $message .= $shipadd1 . "<br>";
 if ($shipadd2) $message .= $shipadd2 . "<br>";
 $message .= $shipcity . ", " . $shipstate . " " . $shipzip;
 $message .= "</p>
      </td>
     </tr>
    </table>

  <table cellpadding='5'>
     <tr>";

//grab the contents of the order and insert them
//into the message field

      $query = "SELECT * from orderdet WHERE ordernum = '$orderid'";
     $results = mysql_query($query)
          or die (mysql_query());
          while ($row = mysql_fetch_array($results)) {
               extract ($row);
               $prod = "SELECT * FROM products
                        WHERE prodNum = '$prodNum'";
               $prod2 = mysql_query($prod);
               $prod3 = mysql_fetch_array($prod2);
               extract ($prod3);
               $message .= "<td>";
               $message .= $quan;
               $message .= "</td>";
               $message .="<td>";
               $message .= $name_frame;
               $message .= "</td>";
               $message .= "<td align='right'>";
               $message .= $costPrice;
               $message .= "</td>";
               $message .= "<td align='right'>";
          //get extended price
               $extprice = number_format($costPrice * $quan, 2);
               $message .= $extprice;
               $message .= "</td>";
               $message .= "</tr>";
               }

 $message .= "<tr>
     <td colspan='3' align='right'>
        Your total before shipping is:
     </td>
     <td align='right'>";
 $message .= number_format($total, 2);
 $message .= "
     </td>
    </tr>
    <tr>
     <td colspan='3' align='right'>
       Shipping Costs:
     </td>
     <td align='right'>";
  $message .= number_format($shipping, 2);
  $message .= "
     </td>
    </tr>
   <tr>
     <td colspan='3' align='right'>
      Your final total is:
     </td>
     <td align='right'> ";
  $message .= number_format(($total + $shipping), 2);
  $message .= "
     </td>
    </tr>
   </table>
</body>
</html>";

/* headers */
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: <sales@globalvision.us>\r\n";
$headers .= "Cc: <sales@globalvision.us>\r\n";
$headers .= "X-Mailer: PHP / ".phpversion()."\r\n";

/* mail it */
mail ($to, $subject, $message, $headers);


//6)show them their order & give them an order number
?>
<HTML>
<HEAD>
<TITLE>Thank you for your order!</TITLE>
</HEAD>
<BODY>
Step 1 - Please Enter Billing and Shipping Information<br>
Step 2 - Please Verify Accuracy and Make Any Necessary Changes<br>
<strong>Step 3 - Order Confirmation and Receipt</strong><br><br>

Thank you for your order!<br><br>
Your order number is <?php echo $orderid ?>. Please print this page or retain
this number for your records.<br>
<br>
Here is a recap of your order:<br><br>
Order date: <?php echo $today ?><br>


<table width="50%" border="0">
  <tr>
    <td>
      <p>Bill to:<br>
        <?php echo $firstname . " " . $lastname ?><br>
        <?php echo $add1 ?><br>
        <?php if ($add2) echo $add2 . "<br>"?>
        <?php echo $city . ", " . $state . " " . $zip ?> </p>
    </td>
    <td>
      <p>Ship to:<br>
        <?php echo $shipfirst . " " . $shiplast ?><br>
        <?php echo $shipadd1 ?><br>
        <?php if ($shipadd2) echo $shipadd2 . "<br>"?>
        <?php echo $shipcity . ", " . $shipstate . " " . $shipzip ?> </p>
    </td>
  </tr>
</table>

<table cellpadding="5">
     <tr>
      <?php
      $query = "SELECT * from orderdet WHERE ordernum = '$orderid'";
     $results = mysql_query($query)
          or die (mysql_query());
          while ($row = mysql_fetch_array($results)) {
               extract ($row);
               $prod = "SELECT * FROM products WHERE prodNum = '$prodNum'";
               $prod2 = mysql_query($prod);
               $prod3 = mysql_fetch_array($prod2);
               extract ($prod3);
               echo "<td>";
               echo $quan;
               echo "</td>";
               echo "<td>";
               echo $name_frame;
               echo "</td>";
               echo "<td align='right'>";
               echo $costPrice;
               echo "</td>";
               echo "<td align='right'>";
          //get extended price
               $extprice = number_format($costPrice * $quan, 2);
               echo $extprice;
               echo "</td>";
               echo "</tr>";
               }
?>
<tr>
<td colspan='3' align='right'>
Your total before shipping is:
</td>
<td align='right'>
     <?php echo number_format($total, 2) ?>
</td>
</tr>
<tr>
<td colspan='3' align='right'>
Shipping Costs:
</td>
<td align='right'>
     <?php echo number_format($shipping, 2) ?>
</td>
</tr>
<tr>
<td colspan='3' align='right'>
Your final total is:
</td>
<td align='right'>
     <?php echo number_format(($total + $shipping), 2) ?>
</td>
</tr>
</table>
</BODY>
</HTML>

 
Old January 4th, 2005, 04:03 PM
Authorized User
 
Join Date: Dec 2004
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default

JEBennett,

I revised my post above, so read it again and see if any of that info helps.

mike

 
Old January 4th, 2005, 06:50 PM
Registered User
 
Join Date: Jul 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I double checked the the names in the database and they are correct.

I am trying to create a email order form in the form of a shopping cart. If I could get this to work it would be perfect.

I was left with the databases from the last webmaster. I had the code working at one point, but associate tried to help me with it and screwed it up.

So I'm left to try and get it working again.

I double checked all the instances of prodNum and checked database for correct spelling.

 
Old January 4th, 2005, 06:57 PM
Authorized User
 
Join Date: Dec 2004
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default

did you check to see if there is really any data in the carttemp table by the time you reach checkout3.php? also, you can insert lines of code periodically throughout the script one section at a time to help narrow down where the problem lies, such as an echo statement inside an if-statement to test whether the if-statement is being parsed.

anyway, i'd go back to the first checkout script and make sure everything is working correctly there and all the necessary POST variables have been posted. then go to checkout2.php and make sure everything is correct there and everything is working as it should. by the time you make it to checkout3.php, you want to make sure once again that the appropriate POST variables have actually been POSTED to checkout3.php. You can accopmlish this with the following code near the top of your script:

Code:
echo "<PRE>";
print_r($_POST);
echo "</PRE>";
The above will print the values of all variables POSTED to that script. Also check that the appropriate databases have been updated. Debugging your code can be a tedious process, so the best way is to logically follow through each step and to make sure that each step is functioning as it should.

one thing i did when debugging the code was remove any data from the all tables except the products table. that way, as each step progressed, i checked the appropriate tables to make sure that the data was inserted correctly.

good luck and let us know how it goes.





Similar Threads
Thread Thread Starter Forum Replies Last Post
return more then one array from class file Komila ASP.NET 2.0 Basics 4 June 27th, 2007 07:10 PM
chapter 15 checkout3.php problem derrida BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 November 12th, 2006 10:11 AM
Array from file fizzerchris Classic ASP Basics 2 March 14th, 2006 08:10 PM
error when sorting an Array of Array nancy VBScript 2 February 17th, 2005 12:57 PM
Text File to Array chadlupkes Javascript How-To 4 September 19th, 2003 09:11 AM





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