Jump to content

Lassie

Members
  • Posts

    390
  • Joined

  • Last visited

Everything posted by Lassie

  1. I have modified the email and it now works to a limited degree. What it does not do is show multiples, only the last purchase. Does my loop need to be in the email body? Any help appreciated. foreach ($cart as $product_id => $qty) { $book = get_book_details($product_id); } extract($book); $to = "$email"; $subj = "test"; $mess = "<html>\n" ."<head>\n" ."<title>Test Mail</title>\n" ."</head>\n" ."<body>\n" ."This is an html email test<br />\n" ."<p><b>Your order has been processed. Please print this email as your reference</b></p>\n" ."<p>Your purchases were:-$title . by . $author </p>\n" ."</body>\n</html>\n"; $mess = wordwrap($mess,70); $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; mail($to,$subj,$mess,$headers);
  2. Thanks for coming back. Do you mean insert the function eg dispay_cart($_SESSION['cart'] or the variables returned from calling this as in '.$book['title'].'by '.$book['author']?
  3. I need to email a reciept of purchase in a cart application. I store the product id and qty in a session variable $cart and then use 2 functions to generate the item, qty, price ,value. This works fine for the display on screen, but I cant figure how to include this in an email to the customer. ideally I would like the same information to display in the email. Any ideas how to approach this would be helpful. email $to = "$email"; $subj = "test"; $mess = "<html>\n" ."<head>\n" ."<title>Test Mail</title>\n" ."</head>\n" ."<body>\n" ."This is an html email test<br />\n" ."<p><b>Your order has been processed. Please print this email as your reference</b></p>\n" ."<p>Your purchases were:-</p>\n" [u][b](Need to insert reciept here)[/b][/u] ."</body>\n</html>\n"; $mess = wordwrap($mess,70); $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; mail($to,$subj,$mess,$headers); display cart function function display_cart($cart, $change = true, $images = 1) { // display items in shopping cart // optionally allow changes (true or false) // optionally include images (1 - yes, 0 - no) echo '<table border = 0 width = "700" cellspacing = 0 align="center"> <form action = "show_cart.php" method = "post"> <tr><th colspan = '. (4+$images) .' bgcolor="#cccccc">Item</th> <th bgcolor="#cccccc">Price</th><th bgcolor="#cccccc">Quantity</th> <th bgcolor="#cccccc">Total</th></tr>'; //display each item as a table row foreach ($cart as $product_id => $qty) { $book = get_book_details($product_id); echo '<tr>'; if($images ==true) { echo '<td align = left>'; if (file_exists('images/$pix')) { /* display picture */ echo "<td><a href='./images/{$book['pix']}' border='0'> <img src= './images/{$book['pix']}' border='0' width='100' height='80'></a></td>\n"; } else echo ' '; echo '</td>'; } echo '<td colspan= "3" align = "right">'; echo '<a href = "show_book.php?product_id='.$product_id.'">'.$book['title'].'</a> by '.$book['author']; echo '</td><td align = "center">£'.number_format($book['price'], 2); echo '</td><td align = "center">'; // if we allow changes, quantities are in text boxes if ($change == true) echo "<input type = 'text' name = \"$product_id\" value = \"$qty\" size = 3>"; else echo $qty; echo '</td><td align = "center">£'.number_format($book['price']*$qty,2)."</td></tr>\n"; } // display total row echo "<tr> <th colspan = ". (5+$images) ." bgcolor=\"#cccccc\"> <th align = \"center\" bgcolor=\"#cccccc\"> ".$_SESSION['items']." </th> <th align = \"center\" bgcolor=\"#cccccc\"> £".number_format($_SESSION['total_price'], 2). '</th> </tr>'; // display save change button if($change == true) { echo '<tr> <td colspan = '. (4+$images) .'> </td> <td align = "center"> <input type = "hidden" name = "save" value = true> <input type = "image" src = "images/save-changes.gif" border = 0 alt = "Save Changes"> </td> <td> </td> </tr>'; } echo '</form></table>'; } get product detail function function get_book_details($product_id) { // query database for all details for a particular book if (!$product_id || $product_id=='') return false; $connection = db_connect(); $query = "select * from products where product_id='$product_id'"; $result = mysql_query($query); if (!$result) return false; $result = mysql_fetch_assoc($result); return $result; }
  4. Thanks for coming back.Yes the order_number is an int. I think you are saying that I can select the product_id form the order contents table and using that query the product table to retirieve the title. This would be good. If that is the case how do I retireve the same set of information for the next order. As it is at present I can get all the orders for a particular customer eg customer 3 has 2 orders 4&5, but I cant work out how to get my query, that gets the product id from the order contents table, to retrieve the details for order 4.It will do just the last numeric order no. Do I need to loop through the query somehow?
  5. I need to combine the result of 2 querys on my database to provide a lists of purchase history information. The logic is:- 1 Select the order_number(s) from the customer order details. 2.Select the product_id and quantity from the order_contents table 3.Using the product_id Select the title of the product form the product table. 4 Put all the variables into an array and print the results. The problem I have is that the whilst the first query returns all the orders from a selected customer the subsequent SELECT querys will return only the last entry. For example a customer may have placed 2 orders, no 4 & 5 but my SELECT query gives me only the detail of order 5.This detail would be the product id which is then used to retireve the product description. Again, the order could have several items and therefore I need the query to return all the product descriptions. I am giving this explantion because I think I am approaching the task wrongly and would welcome any suggestions. My basic question is, how do I retireve multiple results form a select query. I post the product query below as an example of where I have got to. $query= "SELECT product_id From order_contents Where order_number = '$order_number'"; $result = mysql_query($query); while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) { $product_id=$row['product_id']; } $query= "SELECT title FROM products Where product_id = '$product_id'"; $result = mysql_query($query); while ($row = mysql_fetch_array($result)) { $title=$row['title']; }
  6. Just to add that after the first query $order_number does hold multiple values. I echo out $order_number as a debug, but as you say this is not the fact in the second query. Should I be looping through $order_number and running the 2nd query?
  7. Thanks for your reply. How do I populate the variables with multiple values? I am missing something basic I guess.
  8. Hi, Sorry I will restate my problem as follows:- I need to combine the result of 2 querys on my database to provide a lists of purchase history information. The logic is:- 1 Select the order_number(s) from the customer order details. 2.Select the product_id and quantity from the order_contents table 3.Using the product_id Select the title of the product form the product table. 4 Put all the variables into an array and print the results. The errors i encounter are: While the order query gives multiple values ( where applicable) the the query against the order contents only returns 1 record. Similary my array $history only holds 1 record. The database tables are: customer_order order_number , int, auto_inc, primary customer_id, int total, decimal(10) order_date, date order_contents (No primary index set) order_number, int product_id, int quantity, decimal(3 0) price decimal(6 2) ship_date, datetime products product_id, int, auto_inc, primary cat_id, int title, varchar60 product_desc , varchar 255 price, decimal(6.2) The code is:- <p>View Your previous choices</p> <?php //connect to database //retrieve customer_id to query order contents $customer_id=3; $query= "SELECT order_number From customer_order Where customer_id = '$customer_id'"; $result = mysql_query($query); $num_ord = mysql_num_rows($result); if ($num_ord>0) { while($row = mysql_fetch_array($result)) { $order_number=$row['order_number']; echo "$order_number"; } } else { echo "You have no previous purchases"; } //select order items from from order contents and display $query= "SELECT product_id, quantity From order_contents Where order_number = '$order_number'"; $result = mysql_query($query); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $product_id=$row['product_id']; $quantity=$row['quantity']; echo"$product_id"; echo"$quantity"; } $query= "SELECT title FROM products Where product_id = '$product_id'"; $result = mysql_query($query); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $title=$row['title']; echo"$title"; } //create an array to hold the variables $history= array($order_number,$product_id,$title,$quantity,); echo '<pre>'; print_r ($history); echo '</pre>'; // Table header. echo '<table align="center" cellspacing="0" cellpadding="5"> <tr> <td align="left"><b>order Reference</b></td> <td align="left"><b>Product Reference</b></td> <td align="left"><b>title</b></td> <td align="left"><b>Quantity</b></td> </tr> '; // Fetch and print all the records. $bg = '#eeeeee'; // Set the background color. $bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee'); // Switch the background color. echo '<tr bgcolor="' . $bg . '"> <td align="left">'. $history[0] . '</td> <td align="left">'. $history[1] . '</td> <td align="left">'. $history[2] . '</td> <td align="left">'. $history[3] . '</td> </tr> '; echo '</table>'; mysql_free_result ($result); // Free up the resources. mysql_close(); // Close the database connection. // Include the HTML footer file. include ('./includes/footer.html'); ?> i appreciate your help. Lassie
  9. I am trying to show a history of items customers have ordered. This requires retrieving the customer_id the order number and the order contents and then iterating the the items and descriptions. I have several problems. First when i retrieve the product-id and quanitity only the last item is retrieved. Second I thought I would need to use an array to go through the variables and print them but this does not work. $customer_id=1;//set to test code $query= "SELECT order_number From customer_order Where customer_id = '$customer_id'"; $result = mysql_query($query); $num_ord = mysql_num_rows($result); if ($num_ord>0) { while($row = mysql_fetch_array($result)) { $order_number=$row['order_number']; echo "$order_number";//retieves all the order nos for a customer } } else { echo "You have no previous purchases"; } //select order items from from order contents and display $query= "SELECT product_id, quantity From order_contents Where order_number = '$order_number'"; $result = mysql_query($query); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $product_id=$row['product_id']; $quantity=$row['quantity']; echo"$product_id";//only shows last item echo"$quantity"; } //retrieve the title of each product $query= "SELECT title FROM products Where product_id = '$product_id'"; $result = mysql_query($query); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $title=$row['title']; echo"$title"; } //create an array to hold the variables $history= array($order_number,$product_id,$title,$quantity,); echo '<pre>'; print_r ($history); echo '</pre>'; // Table header. echo '<table align="center" cellspacing="0" cellpadding="5"> <tr> <td align="left"><b>order Reference</b></td> <td align="left"><b>Product Reference</b></td> <td align="left"><b>title</b></td> <td align="left"><b>Quantity</b></td> </tr> '; // Fetch and print all the records. $bg = '#eeeeee'; // Set the background color. $bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee'); // Switch the background color. echo '<tr bgcolor="' . $bg . '"> <td align="left">"$history[0]"</td> <td align="left">"$history[1]</td> <td align="left">"$history[2]</td> <td align="left">"$history[3]</td> </tr> '; echo '</table>'; mysql_free_result ($result); // Free up the resources. mysql_close(); // Close the database connection.
  10. I have a development laptop and a server. Both have the same db etc and versions of php,mysql I have a registration script that works on my local m/c but fails on the server(which is not hosted) when trying an insert query. The alias are created in the input check code. I cant see where to look for an error. Any help appreciated. $query = "SELECT user_id FROM users WHERE email='$e'"; $result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error()); if (mysql_num_rows($result) == 0) { // Available. // Create the activation code. $a = md5(uniqid(rand(), true)); // Add the user. $query = "INSERT INTO users (email, pass, first_name, last_name, active, registration_date) VALUES ('$e', SHA('$p'), '$fn', '$ln', '$a', NOW() )"; $result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error()); if (mysql_affected_rows() == 1) { // If it ran OK. An error occurred in script 'c:\easyserv\www\reg\register.php' on line 65: Query: INSERT INTO users (email, pass, first_name, last_name, active, registration_date) VALUES ('hawkesleyhouse@btinternet.com', SHA('horatio1'), 'Ray', 'Pocock', 'f585bac1567c50d878e3a8490399210e', NOW() ) MySQL Error: You have an error in your SQL syntax near '('horatio1'), 'Ray', 'Pocock', 'f585bac1567c50d878e3a8490399210e', NOW() )' at line 1 Date/Time: 2-20-2007 18:09:17 error message
  11. Thanks Huggie. I have now completed my cart as a basic end to end job and now need to tidy up ( a lot) and add some better security/checking. thanks again Lassie
  12. Hi Huggie, Sorry I'm going mad.The result is as expected.I just read it wrongly. Many thanks for your help. I will study your approach and see what I can learn from it. Lassie
  13. Hi Huggie, Thanks for that. I still seem to get only one return item. This is the debug line Array ( [2] => 1 [6] => 1 ) '2', '6'Array ( [2] => Salad Recipes.pdf [6] => How to Buy a Car With Little or no credit.pdf ) [2] is the correct prod id for Salad etc but not the file. the file is in the record for product 6. the products 2 & 6 were the ones selected so thats Ok. Dont think the pids were listed as planned. I have shown the table structure below. The product_id is the primary. Thank you for your continued interest and help. Field  Type  Null  Default product_id  int(4) No  cat_id  int(3) No  0 title  varchar(60) No  product_desc  varchar(255) No  price  decimal(6,2) No  0.00 pix  varchar(30) No  type  varchar(20) No  added_date  date No  0000-00-00 author  varchar(40) No  isbn  varchar(13) No  Featured  int(1) Yes  NULL New  int(1) Yes  NULL business  int(1) Yes  NULL promo_link  varchar(60) No  dl_link  varchar(60) No 
  14. I had some further thoughts on my problem. I know that my var $cart contains the product_ids and that is what ineed to query the db. Therefore I have used the array_keys() and the list() to try and get a var containing th eproduct values. the modfifcation is [code] function display_dl_link2($cart) { echo '<pre>'; print_r ($cart); echo '</pre>'; $keys=array_keys($cart); echo '<pre>'; print_r ($keys); echo '</pre>'; list($product_id)=$keys; echo "$product_id"; $connection = db_connect();      $query = "select dl_link from products where product_id='$product_id'";   $result = mysql_query($query);   $numRows = mysql_num_rows($result);   echo "$numRows";   if (!$result)   { mysql_error(); return false; } else {     $result = db_result_to_array($result);       return $result; } echo"<br /><br />"; } $connection = db_connect();      $query = "select dl_link from products where product_id='$product_id'";   $result = mysql_query($query);   $numRows = mysql_num_rows($result);   echo "$numRows";   if (!$result)   { mysql_error(); return false; } else {     $result = db_result_to_array($result);       return $result; } } [/code] Unfortunately I am no further forward. My de bug shows Array (     [2] => 1     [6] => 1 ) Array (     [0] => 2     [1] => 6 ) 2//the value of the first prod id 1//no of rows returned from query I would be very grateful for any advice .
  15. I am passing the product id so that i can select all the links that correspond the all the products passed. I think you are right. There is something wrong at this point. If i count the rows returned from the query I only get one. I put this in [code] $query = "select dl_link from products where product_id='$product_id'";   $result = mysql_query($query);   $numRows = mysql_num_rows($result);   echo "$numRows"; [/code] debugs show The value of 2 is 1 The value of 3 is 1 1//numof rows returned Array (     [0] => Array         (             [dl_link] => 31 days to bigger arms.pdf         ) ) When you say overwritten could you explain.I think this is my problem. Thanks
  16. Ok. I tried that and get the same result eg The value of 2 is 2 The value of 3 is 1 Array (     [0] => Array         (             [dl_link] => 31 days to bigger arms.pdf         ) ) The other problem is that the result to array is used eleswhere so for this should it be called something else? Thank you for your help
  17. Hi, Thanks for coming back. I afraid I made a mistake in the code I posted. The code should read following the query. [code] else { $result = db_result_to_array($result);   return $result; [/code] running this I get this from my print_r Resource id #15
  18. I need to search a product file and retireve multiple links. I have checked my code has multiple product codes, but my query seems to only return the last item. I want to return the result as an array from which I can then build links to download folders. My code is:- [code] $dl_link=display_dl_link2($_SESSION['cart'],'product_id'); function display_dl_link2($cart,$product_id) { foreach ($cart as $product_id => $qty) { echo "The value of $product_id is $qty<br />";//debug to check have prod ids shows } //The value of 2 is 1 //The value of 3 is 1   if (!$product_id || $product_id=='')   {     return false;     } $connection = db_connect();      $query = "select dl_link from products where product_id='$product_id'";   $result = mysql_query($query);   if (!$result)   { mysql_error(); return false; } else { $result = mysql_fetch_assoc($result);   return $result; { } } } //results to array function function db_result_to_array($result) {   $res_array = array();   for ($count=0; $row = mysql_fetch_assoc($result); $count++)   $res_array[$count]=$row;     return $res_array; } [/code] used print_r to check contents of $dl_link which shows Array (     [dl_link] => 31 days to bigger arms.pdf ) I have also checked the database has the fields populated. Any help much appreciated.
  19. Problem solved. I re did the script on a new page and it know works. The only error i found was the redirection url was wrong. so may be that was it along with the other points made in the discussion. Thanks everybody for your help. Lassie
  20. Tried it again with that amendment and still no joy. I also need to create a session var just before the redirect so the code now has an addition as follows. [code] if (@mysql_num_rows($result) == 1) { $hash = $hash."/"; $_SESSION['hash']= $hash; header('Location:http://217.46.159.226/e_cart9/Downloads/index.php'); $ok = "Match Made";     } [/code] Does this break any rules? Is there another way of approaching this. I need to pass the variables to effect a download script.Since the visitor arrives at the the current page from an email link i dont want put a form  or link in. Any thoughts appreciated. Lassie
  21. Thanks. Again I tried it and get the same error. I dont understand this as I have verified that the $_GET does have the variable, yet this is the area where my code gives the error message, but the header seems to be the villan in the piece. I will add below the top and bottom of the scriprt as it now is if you have any more advice. Thank you. [code] <?php ob_start();?> <?php require ('book_sc_fns.php'); session_start(); //the rest of the script echo "$ok<br />\n"; echo "$hash"; ob_end_flush(); ?> [/code]
  22. Hi, Thanks. I tried that and still get the same error. What does the function aim to do?
  23. I have the following piece of code which is designed to test for a $_GET compare with the database value and if ok redirect to a new page. If I dont insert the header line the program matches the var and all is well. If I insert the header line i generate 'there was an error message'. I have an errors array to catch the errors and print them after the header function is called. I dont get a headers sent warning. Anyone see where I go wrong? [code] <?php require ('book_sc_fns.php'); session_start(); include("misc.inc"); $connection = mysql_connect($host,$user,$password)    or die ("$connection:".mysql_error($connection)); $db = mysql_select_db($database,$connection)          or die ("$db:".mysql_error($connection)); $errors = array(); //retrieve the hash if (isset($_GET['pur_id'])) { $hash = $_GET['pur_id']; }else{ $errors[]= "there was an error";//message I get if header line left in } //query db for match $query = "SELECT hash FROM pick_up WHERE hash='$hash'";   $result = mysql_query($query)or die(mysql_error());   if (@mysql_num_rows($result) == 1) { // header('Location:http://xxxxxxxxxxxxxxx/e_cart9/pick_up.php'); $ok = "Match Made";     }     else{ $errors[] =  "No Match made"; } If(!empty($errors)) { echo '<h1>Error!</h1> <p>The following error occured:<br />'; foreach ($errors as $msg) { echo " - $msg<br />\n"; } } echo "$ok<br />\n"; echo "$hash"; exit(); ?> [/code]
×
×
  • 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.