Jump to content

roldahayes

Members
  • Posts

    287
  • Joined

  • Last visited

Posts posted by roldahayes

  1. No,  awr100-1322.php is the page URL.

     

    I want the code within the page to read the url and populate itself with the page url (minus the .php)

    i.e

     $CODE = "Page URL Here"; 

    At the moment, I have to manually open the page and change the $CODE to what ever the page Url is - I want this to happen dynamically

  2. I just want to make sure that I have explained myself correctly in my original post.

     

     

    My full URL's are like this:

    http://mysite.com/PPP/awr99-1322.php

     

     

    Within my code  I have:

    $CODE = "awr99-1322"; (This then generates everything on my page to be working correctly)

     

     

    I need the $CODE="---------";   to be generated every time depending on url name.

     

     

    So for example,  if the url was:

    http://mysite.com/PPP/awr100-1322.php

     

    Then the code would end up as,  $CODE = "awr100-1322";

  3. Hi,

     

    Is it possible to dynamically change a variable depending on the URL of the page?

     

    i.e

     

     

    my code on the page is:  $CODE = "somethinghere";

     

    if the page url is www.domain.com/654321.php

     

    it chages it to $CODE = "654321";

     

     

    I hope I've explained this correctly!

     

     

  4. Just one last question, how would I be able to get a line break after each output to make it more readable?

     

    I'm assuming I need "\n" somewhere in

     

    // For each value pair, output value to LOG
    $firstvalue=TRUE;
    foreach ($_POST as $key => $value)  {
    if (!$firstvalue) { fwrite($log, ", ") ; }
  5. Solved,

     

    // Open LOG File$log = fopen ("formdata.log" , "a");  // For each value pair, output value to LOG$firstvalue=TRUE;foreach ($_POST as $key => $value)  {if (!$firstvalue) { fwrite($log, ", "); }   // If value is array (multiple select list)// Output array to LOG (elements sep by -)if (is_array($value) ) {$firstelement=TRUE;fwrite ($log, "\" ");foreach ($value as $element) {if (!$firstelement) {fwrite ($log, "-");$firstelement=FALSE;}fwrite ($log,$element); }} else { // Not array, output simple valuefwrite ($log, "\" $value ");$firstvalue=FALSE;} } // Line Feed and Close LOG fwrite ($log, "\n");fclose ($log);
    

     

    Thanks for looking

  6. Hi,

     

    I am having an issue with certain browsers not being able to receive the data from a $POST form.

     

    Could anyone advise a way of getting it to log what is being passed from the form and place it in a text file  please?

    <html>
    <body onLoad="document.myForm.submit();">
    <form action="https://secure2.epdq.co.uk/cgi-bin/CcxBarclaysEpdq.e" method="post" name="myForm">
                
              <?php  $user_agent = "Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)";?>         
    <? foreach($_POST as $i => $v) { ?>
    <input type="hidden" name="<?= $i ?>" value="<?= $v ?>" />
    <? } ?> 
    <input type="submit" value="If you are not automatically redirected, please click here" />
    </form>
    </body>
    </html>
    
  7.  

     

    i'm surprised you are still trying to get this code to work. you could have completely rewritten it by now and gotten it to do what you want.

     

    ​Ha! Thats what I am finally getting round to doing! 

     

    Please ignore the html and the way I have posted, I have just cleared out the code to post here.

     

    I'll go through your post and see what I can do,

     

    Many thanks for helping (again) :)

  8. Hi,

     

    I have this code that runs a simple shopping cart.

     

    I'm having an issue where the basket quantities are only updating when there is 1 or 2 lines of products in there.

     

    Any more than that and the line keep defaulting back to quantity 1

     

    Is there anything obvious that I have got wrong here?

     

    Thanks.

     

    <?phpheader("Content-type: text/html; charset=utf-8");session_start(); include_once("head.php");include_once("usr_conn.php");if(!connectDB()) { echo "<p>Unable To Connect To Database</p>"; return; }     if (isset ($_GET['src']))   {     $_SESSION['returnTo'] = $_GET['src'];   } $urlref = $HTTP_REFERER; $prodID = htmlentities ($_GET['productID']); $delete = htmlentities ($_GET ['delete']); $quantity = htmlentities ($_GET['quantity']); $updateQuantity = htmlentities ($_GET['updateQuantity']); $update = htmlentities ($_GET ['update']); $currency = "£"; // maximum querys per user basket $MAXBASKETQUERY = 25; // start the html table?>  <?php// check if user has no cookie set if ($userID == "") { ?><div class="alert alert-danger">No Product Querys made yet </div>                 <?php return; } //if the updated quantity is 0 or blank remove item from basket if ($updateQuantity == '0'){ $delete = 'yes'; } if (($update == 'yes')&& ($updateQuantity == '')){ $delete = 'yes'; } // if delete parameter set to yes run the delete code if ($delete == 'yes') { // if prodID is set, delete that specific product from this userID's basket if ($prodID != "") { $sqlquery = "DELETE FROM basket WHERE userID = '" . $userID . "' AND  productID = '" . $prodID . "'"; $result = mysql_query($sqlquery); if ($result) { ?>                                      <div class="alert alert-danger">Item Deleted. Click <a href="update.php"><font color="#990000">Here</font></a> to refresh the basket </div><?php } else { ?>                 <div class="alert alert-danger">Unable To Delete <br />                       Item Click <a href="update.php">Here</a> to refresh                                              the basket</div>                 <?php }   mysql_close(); return; } } //update the shopping basket quantity if ($update == 'yes') { // if prodID is set, delete that specific product from this userID's basket if ($prodID != "") { $sqlquery = "UPDATE basket SET quantity = '" . $updateQuantity . "' WHERE productID = '" . $prodID . "'AND userID = '" . $userID . "'"; $result = mysql_query($sqlquery); if ($result) { ?>                 <div class="alert alert-danger">Your basket has been updated.</div>                 <?php } else { ?>                 <div class="alert alert-danger">Your basket has NOT been updated</div>                 <?php }   } } // find the number of rows in this userID's basket $sqlquery = "SELECT * FROM basket WHERE userID = '" . $userID . "'"; $result = mysql_query($sqlquery); if (!$result) { echo "<p><font class=error>Could not find any entrys for this Basket</small></p>"; mysql_close(); return; } else $rowCount = mysql_num_rows($result); // if prodID is set new product is passed in, add/update the userID's basket if ($prodID != "") { // find if the prodID already exists in this userID's basket $sqlquery = "SELECT * FROM basket WHERE userID = '" . $userID . "' AND productID = '" . $prodID . "'"; $result = mysql_query($sqlquery); $rowCount = mysql_num_rows($result); // if no matches  insert the product into the userID's basket if ($rowCount == 0) { // find number of items in basket $sqlquery = "SELECT * FROM basket WHERE userID = '" . $userID . "'"; $result = mysql_query($sqlquery); $rowCount = mysql_num_rows($result); // check if the maxquery's has been reached if ($rowCount > ($MAXBASKETQUERY - 1)) { echo ("<p><font class=error>Only $MAXBASKETQUERY overall orders are allowed, your product could not be added to basket</font></p>"); } else { $expiretime = time() + 7200; $sqlquery = "INSERT INTO basket" . $basketFields . "VALUES ('" . $prodID . "', '1', '" .$userID . "', '" . $expiretime . "')"; $result = mysql_query($sqlquery); if (!$result) echo "<font class=error><p>Could not add item to Basket</p></font>"; } } } // select the userID's basket query and the Product Reference relating to each of the basket's productID's $sqlquery = "SELECT products.Prod_REF, basket.productID, basket.quantity, products.Prod_Make, products.Prod_Model, products.Prod_Type, products.Car_Make, products.Car_Model, products.Price_ExVat, products.Post_ID, Product_Desc FROM basket INNER JOIN products ON basket.productID = products.Prod_ID WHERE ((basket.userID) = '" . $userID . "')"; $result = mysql_query($sqlquery); $rowCount = mysql_num_rows($result); // echo $sqlquery;  // *debug // assign the table headers //$dbFields = array( "Reference", "Product Query"); // check if no entries in basket if (!$result || (mysql_num_rows($result) == 0)){ ?>                 <div class="alert alert-danger">No Product Queries                                              In Basket.</div>                 <?php } else //*************display contents of basket////////////////////////////////////////////////////// { // echo each header from array //foreach ($dbFields as $headIndex) // echo an extra blank header for the delete item column // fetch each row as an associative array $counter = 1; $price = 0; //set default postage value outside loop$postagerate = 15.00; while ($row = mysql_fetch_assoc($result)){  //decide which postage value is the highest and use that to calculate overall price  //get the postage values for each product  $sqlpostquery = "SELECT * FROM postage WHERE Post_ID = '" . htmlspecialchars($row['Post_ID']) . "'";   //get the postage values from the database  $postresult = mysql_query($sqlpostquery);  $rowpost = mysql_fetch_assoc($postresult);   // check if postage value was available  if ($postresult || !(mysql_num_rows($postresult) == 0))    {    $rawpostage = htmlspecialchars($rowpost['Post_Cost']) ? htmlspecialchars($rowpost['Post_Cost']) : 0.00;     //get the lowest postage rate.    if ($postagerate > $rawpostage)      {        $postagerate = $rawpostage;    }  }  else  {    $postagerage = 0.00;  }   //round postage rate of 2 decimal places  $postagerate = $postagerate;   //release the postage resultset array   mysql_free_result($postresult);   echo "<form action=basket.php method=get name=form".$counter.">     <input name=update type=hidden value=yes>     <input name=productID type=hidden value=". $row['productID'] ."><tr class=stdtable>";          ?>  <form method="post" action="">                                                                                                                                  <table border="0" cellspacing="0" cellpadding="0" width="100%" class="responsive shop_table cart" data-responsive-mode="stack">    <thead>      <tr>        <th>Part No.</th>        <th >Description</th>        <th>QTY</th>        <th>ex vat</th>        <th>inc vat</th>        <th>Total Price</th>        <th>Remove</th>                              </tr>    </thead>    <tbody>      <tr>                                 <!-- This is the block that will echo the basket columns  -->         <td class= partno table-striped mb-none><?php echo("" . htmlspecialchars($row['Prod_REF']) . "");?></td>         <td class= descrip table-striped mb-none><?php echo("" . htmlspecialchars($row['Product_Desc']) . "");?></td>         <td class= table-striped mb-none><?php echo (" <input name=updateQuantity onchange=submit(); type=text size=2 value=". htmlspecialchars($row['quantity']));?> </td>         <td class= table-striped mb-none><?php echo ("". $currency . number_format(htmlspecialchars($row['Price_ExVat']), 2) ."");?></td>         <td class= table-striped mb-none><?php echo ("". $currency . number_format(calcVAT($row["Price_ExVat"]), 2) ."");?></td>         <td class= table-striped mb-none><?php echo ("". $currency . number_format(((calcVAT($row["Price_ExVat"]* $row['quantity']))), 2) ."");?></td>         <td class= table-striped mb-none><?php echo "   <a href=\"basket.php?delete=yes&productID=" . $row['productID'] . "\">  <i class=\"fa fa-times\">"; ?></td>      </tr>                                            </table>                                               <!-- End of this section  -->                                                                    <?php    $counter ++;   //get a cumulative value of the price as items are added to the basket and multiply by quantity as we go.   $price = $price + (calcVAT (htmlspecialchars($row['Price_ExVat']))) * htmlspecialchars($row['quantity']);  } //assign subtotal and round to 2 decimal places $subtotal = $price; $total = $subtotal + $postagerate; //pick overall postage type if ($postagerate == 5) $postage = 3; else if ($postagerate == 9) $postage = 2; else if ($postagerate == 10) $postage = 1; } //update shopper table with new/changed info $sqlshopper = "SELECT * FROM shopper WHERE User_ID = '" . $userID . "'"; //echo "query: " . $sqlshopper; $result = mysql_query($sqlshopper); $rowCount2 = mysql_num_rows($result); //add shopper if ($rowCount2 == 0) { $sqladd = "INSERT INTO shopper" . $shopperFields . "VALUES ('" . $userID . "', '" . $total . "', '" . $postage . "')"; //echo "noshopper: " . $sqladd; $shopadd = mysql_query($sqladd); if (!$shopadd) echo "<font class=error><p>Your basket has not been processed</p></font>"; } else { //update details $sqlupdate = "UPDATE shopper SET Basket_total = '" . $total . "', Postage = '" . $postage . "' WHERE user_ID = '" . $userID . "'"; //echo "shopper: " . $sqlupdate; $shopupdate = mysql_query($sqlupdate); if (!$shopupdate) echo "<font class=error><p>Your basket has not been updated</p></font>"; } // finish table ?>                                                                                                                                                                        <?php  echo $currency;  echo number_format($subtotal, 2);  ?></span></td></tr><tr class="shipping" style="font-size: 18px"><th>Delivery</th><td><span class="header"> <?php  echo $currency;  echo number_format($postagerate, 2);  ?></span></td></tr><tr class="total"><th><strong>Order Total</strong>(inc vat)</th><td><strong><span class="amount"><?php  echo $currency;  echo number_format($total, 2);  ?></span></strong>                                  </form><?php   mysql_free_result($result);   mysql_close(); ?>
    

  9. This code was written years ago so I am now trying to sort the styling out with CSS and removing all the inline stuff.  Also, there is so much code that as you've advised, needs streamlining......

     

     

     

    Ok, I have made a quick example image of what I am trying to achieve,

     

    The database is populated by uploading a CSV file.

     

    Each section of the results has a unique code (RB, BH, RA etc)

     

    I want each section to appear in the divs as in the picture (div-RB, div-BH, div-RA)

     

     

     

    divs.jpg

  10. Hi,

     

    Please have a look at this code that I have - it is the results page of a "make" & "model" vehicle search.  It displays the product results in a table in sections depending on the case that has been entered to populate the database.

     

    I am trying to clean up all of this code and incorporate it into Divs instead of tables.

     

    My question is how would I go about structuring this to display the results in different divs rather than the coloured tables that it is now doing.

     

    Any help would be great.

     

    <?php //info bars colour$color_info="#D6D685"; // Almost Silver //FFFFCC$color1="#E9E9E9";// Light Blue$color2="#EAD5FF";// Light Blue  include_once("func_lib.php");include_once("usr_conn.php");if (!connectDB()){echo "<p>Unable To Connect To Database</p>";return;}if (($_GET ['make'] == "MAKE") or ($_GET ['model'] == "MODEL")){$errMessage =  "<br><br><b><font class=small>Your search hasn't returned any results, please re-enter your search again.</font></b><br><br><a href=van_accessories.php>Search again</a><br><br>"; }else{$strMake = mysql_escape_string($_GET ['make']);$strModel = mysql_escape_string($_GET ['model']);}$strDefaultProd = "XD";//write query string that will pased in paging links$strQuery = "make=".$strMake."&model=".$strModel."&";//echo $strQuery;$page = mysql_escape_string($_GET ['page']);$sqlSelect = "SELECT Prod_ID, Prod_Type, Prod_Model, Prod_Make, Prod_REF, Product_Desc, Price_ExVat, image_name FROM products";$criteria = " WHERE (Car_Make = '".$strMake."' AND Car_Model = '".$strModel."' AND Default_Code = 'CV') OR (Car_Make = '".$strMake."' AND Car_Model = '".$strModel."' AND Default_Code = 'LE') OR (Car_Make = 'all' AND Default_Code = 'RA')";$sqlquery = $sqlSelect . $criteria; $result = mysql_query($sqlquery);$count = mysql_num_rows($result);$full_count = $count; $records_per_page = 999;$total_pages = ceil( $count / $records_per_page );if ( $page == "" ) { $page = 1; }if ( $page == 1 ) {    $naviagation = "<font color=\"#666666\">First</font> | <font color=\"#666666\">Prev</font> | "; } else {     $prev_page = $page - 1;    $navigation = "<a href=\"van_roof_rack_results.php?".$strQuery."page=1\">First</a> | <a href=\"van_roof_Rack_results.php?".$strQuery."page=".$prev_page."\">Prev</a> | ";}if ( $page == $total_pages ) {} else {     $next_page = $page + 1;    $navigation .= "<a href=\"van_roof_rack_results.php?".$strQuery."page=".$next_page."\">Next</a> | <a href=\"van_roof_rack_results.php?".$strQuery."page=".$total_pages."\">Last</a>";}$offset = ( $page - 1 ) * $records_per_page;$sqlSelect = "SELECT Car_Make, Car_Model, Prod_ID, Prod_Type, Prod_Model, Prod_Make, Priority, Prod_Code, Prod_REF, Product_Desc, Price_ExVat, Link, image_name FROM products";$criteria = " WHERE (Car_Make = '".$strMake."' AND Car_Model = '".$strModel."' AND Default_Code = 'CV') OR (Car_Make = '".$strMake."' AND Car_Model = '".$strModel."' AND Default_Code = 'LE') OR (Car_Make = 'all' AND Default_Code = 'RA')"; $limit = " ORDER BY Priority ASC, Prod_Code ASC, Prod_ID ASC LIMIT $offset, $records_per_page";$sqlquery = $sqlSelect . $criteria . $limit ;$result = mysql_query($sqlquery);if (!$result || (mysql_num_rows($result) == 0)){}else{$count = mysql_num_rows($result); }?> <h1><?php echo("<font class=vehicle> " . $strMake . " " . $strModel ."</p>"); ?></h1>  <!--Start of results code -->                                               <?php     $title .= "</tr>"; //set the counters for the records results display screen$cnt = 0;$headercount1 = 0;$headercount2 = 0;$headercount3 = 0;$headercount4 = 0;$headercount5 = 0;$headercount6 = 0;$headercount7 = 0;while ($row = mysql_fetch_assoc($result)){$strLength = strlen ($row["Prod_Type"]);$strPrefix = substr($row["Prod_Type"], 0, 2);$strSuffix = substr($row["Prod_Type"], 2, $strLength);echo "<tr align=center><td colspan=7 class=small>";  //set bg cell color diff for BH makeswitch ($strPrefix){case "BH":$color=$color2;break; default:$color=$color1;break;}//end switch  switch ($strPrefix){   case "BH":        if ($headercount1 == 0) { echo "<img border=0 src=bulkheads.jpg alt=Bulkheads></td></tr>";echo $title;}$headercount1 ++; //$headercount1        break;   case "RB":       if ($headercount2 == 0){echo "<img border=0 src=roofracks.jpg alt=Roof-Bars></td></tr>";echo $title;} $headercount2 ++; //$headercount1       break; case "BX":       if ($headercount3 == 0){ echo "<img border=0 src=bulkheads.jpg alt=Roof-Boxes></td></tr>";echo $title;}$headercount3 ++; //$headercount1       break;case "BR":         if ($headercount4 == 0) { echo "<img border=0 src=bulkheads.jpg alt=Bike-Racks></td></tr>"; echo $title; }  $headercount4 ++; //$headercount1       break;case "SR":       if ($headercount5 == 0) {echo "<img border=0 src=bulkheads.jpg alt=Ski-Rack></td></tr>";echo $title;} $headercount5 ++;  //$headercount1        break;case "CR":        if ($headercount6 == 0) {echo "<img border=0 src=bulkheads.jpg alt=Canoe-Rack></td></tr>";   echo $title;}  $headercount6 ++; //$headercount1       break; case "XD":  if ($headercount7 == 0) {  echo "<img border=0 src=general.jpg alt=General-Accessories></td></tr>";echo $title; }   $headercount7 ++;  }//print a product row if the prodtype isn't set to INFO$pop_link = "";if ($strSuffix != "INFO"){//test to see if an image exists for the productif ($row["Link"] <> NULL){$pop_link = "   <a href=\"products/".$row["Link"]."?iframe=true&width=650&height=500\" rel=\"prettyPhoto\" >More information >>>></a>";}?>                                                                                                                                                                                      <?PHP if (isset($errMessage)){echo $errMessage;}if (!$result || (mysql_num_rows($result) == 0))echo ("<b><font class=small>Product Tyoe Not Found For Your Vehicle.</font></b><br><br>");// display the resultselse{// use rowcount to display total results found//*debugecho $navigation;}?>                                               <?php   $title =  "<tr align=\"center\" class=\"headertable\" height=\"32\">";  $title .= "<td width=\"2%\"><img src=\"images/transparent.gif\" width=\"95\" height=\"1\" /></td>";     $title .= "<td width=\"2%\">Make</td>";       $title .= "<td width=\"1%%\">Ref No.</td>";       $title .= "<td width=\"1%\">Title/Description</td>";       $title .= "<td width=\"1%\">Price Ex VAT</td>";       $title .= "<td width=\"73\">Price Inc VAT</td>";       $title .= "<td width=\"60\"><img src=\"2003/basket.gif\" width=\"21\" height=\"14\"></td>";       $title .= "</tr>"; $cnt = 0;$headercount1 = 0;$headercount2 = 0;$headercount3 = 0;$headercount4 = 0;$headercount5 = 0;$headercount6 = 0;$headercount7 = 0;while ($row = mysql_fetch_assoc($result)){$strLength = strlen ($row["Prod_Type"]);$strPrefix = substr($row["Prod_Type"], 0, 2);$strSuffix = substr($row["Prod_Type"], 2, $strLength);echo "<tr align=center><td colspan=7 class=small>"; //set bg cell color diff for BH makeswitch ($strPrefix){case "BH":$color=$color2;break; default:$color=$color1;break;}//end switch  switch ($strPrefix){   case "BH":        if ($headercount1 == 0) { echo "<img border=0 src=bulkheads.jpg alt=Bulkheads></td></tr>";echo $title;}$headercount1 ++; //$headercount1        break;   case "RB":       if ($headercount2 == 0){echo "<img border=0 src=roofracks.jpg alt=Roof-Bars></td></tr>";echo $title;} $headercount2 ++; //$headercount1       break; case "BX":       if ($headercount3 == 0){ echo "<img border=0 src=bulkheads.jpg alt=Roof-Boxes></td></tr>";echo $title;}$headercount3 ++; //$headercount1       break;case "BR":         if ($headercount4 == 0) { echo "<img border=0 src=bulkheads.jpg alt=Bike-Racks></td></tr>"; echo $title; }  $headercount4 ++; //$headercount1       break;case "SR":       if ($headercount5 == 0) {echo "<img border=0 src=bulkheads.jpg alt=Ski-Rack></td></tr>";echo $title;} $headercount5 ++;  //$headercount1        break;case "CR":        if ($headercount6 == 0) {echo "<img border=0 src=bulkheads.jpg alt=Canoe-Rack></td></tr>";   echo $title;}  $headercount6 ++; //$headercount1       break; case "XD": if ($headercount7 == 0) {  echo "<img border=0 src=general.jpg alt=General-Accessories></td></tr>";echo $title; }   $headercount7 ++;  }  //print a product row if the prodtype isn't set to INFO   $pop_link = "";if ($strSuffix != "INFO"){//test to see if an image exists for the productif ($row["Link"] <> NULL){$pop_link = "   <a href=\"products/".$row["Link"]."?iframe=true&width=650&height=500\" rel=\"prettyPhoto\" >More information >>>></a>";}echo "<tr class=stdtable align=center height=25>";  //DISPLAY THUMB IMAGE IF ONE WAS LISTED IN THE image_name FIELD$p_image_name = htmlspecialchars($row["image_name"]);//echo "p_image_name:$p_image_name";if ($p_image_name != "")echo "<td bgcolor=$color width=\"95\"><img src=\"images/product_images/$p_image_name\" border=\"0\" /></td>";elseecho "<td bgcolor=$color width=\"95\"><img src=\"images/transparent.gif\" width=\"95\" height=\"50\" border=\"0\" /></td>";echo "<td bgcolor=$color width=\"60\">". htmlspecialchars($row["Prod_Make"]) ."</td><td bgcolor=$color width=\"60\">" . htmlspecialchars($row["Prod_REF"]) . "</td><td bgcolor=$color align=left class=\"infolink\" width=\"550\">" . htmlspecialchars($row["Product_Desc"]) .$pop_link . "</td><td bgcolor=$color width=\"73\">£" . number_format(htmlspecialchars($row['Price_ExVat']), 2) ."</td><td bgcolor=$color width=\"73\">£" . number_format((calcVAT (htmlspecialchars($row['Price_ExVat']))), 2) ."</td><td class=\"btn btn-default btn-sm\"><a href=basket.php?src=".urlencode($_SERVER['REQUEST_URI'])."&productID=" . $row["Prod_ID"] . ">BUY</a></td></tr>";}// if the prod type is set to INFO then print out a new row for that informationelse { echo "<tr class=stdtable align=center height=25 ><td colspan=7 bgcolor=$color_info><em><strong>" . htmlspecialchars($row["Product_Desc"]) . "</strong></em></td></tr>";  } } ?> <?phpmysql_free_result($result);mysql_close();}}?>
    

     

     

  11. Thanks for the great advice.

     

    I have read up on JOIN'ed queries and can see the logic in the way you have suggested.

     

    Now i'm going to spend some time on clearing up the necessary code to make life easier in the future!

     

    Thanks again,

  12. Thanks for the replys.

     

     

    you, or who originally wrote this, easily have two times more php code that what is needed, resulting in it taking 5-10 times longer to find and fix any problems or just make changes to what the code is doing

     

    This is exactly the problem that I am having.... The code was written a few years ago by someone else and I have tacked bit and pieces on over the last few years so I'm totally lost with it all to be honest....

     

    From what I can see, the following code has all of the postage block info in it.

     

    I dont actually need the $postagerate=15.00;  part at all....  as each product in the database has a Post_Cost associated to it, it just needs to select the highest of all of these.

     

    <?php$sqlquery = "SELECT products.Prod_REF, basket.productID, basket.quantity, products.Prod_Make, products.Prod_Model, products.Prod_Type, products.Car_Make, products.Car_Model, products.Price_ExVat, products.Post_ID, Product_Desc FROM basket INNER JOIN products ON basket.productID = products.Prod_ID WHERE ((basket.userID) = '" . $userID . "')"; $result = mysql_query($sqlquery);$rowCount = mysql_num_rows($result); if (!$result || (mysql_num_rows($result) == 0)){ } else //*************display contents of basket////////////////////////////////////////////////////// { // echo each header from array //foreach ($dbFields as $headIndex) // echo an extra blank header for the delete item column // fetch each row as an associative array $counter = 1; $price = 0;  //set default postage value outside loop$postagerate = 15.00; while ($row = mysql_fetch_assoc($result)){  //decide which postage value is the highest and use that to calculate overall price  //get the postage values for each product  $sqlpostquery = "SELECT * FROM postage WHERE Post_ID = '" . htmlspecialchars($row['Post_ID']) . "'";   //get the postage values from the database  $postresult = mysql_query($sqlpostquery);  $rowpost = mysql_fetch_assoc($postresult);   // check if postage value was available  if ($postresult || !(mysql_num_rows($postresult) == 0))    {    $rawpostage = htmlspecialchars($rowpost['Post_Cost']) ? htmlspecialchars($rowpost['Post_Cost']) : 0.00;     //get the lowest postage rate.    if ($postagerate > $rawpostage)      {        $postagerate = $rawpostage;    }  }  else  {    $postagerage = 0.00;  }   //round postage rate of 2 decimal places  $postagerate = $postagerate;   //release the postage resultset array   mysql_free_result($postresult);   echo "<form action=basket.php method=get name=form".$counter.">     <input name=update type=hidden value=yes>     <input name=productID type=hidden value=". $row['productID'] ."><tr class=stdtable>";   echo("<td align=center> " . htmlspecialchars($row['Car_Model']) . "</td>");   echo("<td align=center> " . htmlspecialchars($row['Prod_REF']) .  "</td>");   echo("<td align=left>" . htmlspecialchars($row['Product_Desc']) . "</td>");   //echo("<td align=center>". htmlspecialchars($row['Prod_REF']) ."</td>");   // for the final column echo an hyperlink to delete the product entry     //settype($row["Price_ExVat"], "integer");   echo "<td align=center><input name=updateQuantity onchange=submit(); type=text size=2 value=". htmlspecialchars($row['quantity'])."></td><td align=center>". $currency . number_format(htmlspecialchars($row['Price_ExVat']), 2) ."</td><td align=center>". $currency . number_format(calcVAT($row["Price_ExVat"]), 2) ."</td><td align=center>". $currency . number_format((calcVAT (htmlspecialchars($row['Price_ExVat'] * $row['quantity']))), 2)  ."</td>";   echo "<td align=center><a href=\"basket.php?delete=yes&productID=" . $row['productID'] . "\"><img src=2003/remove.gif border=0></a></td>";   echo "</tr></form>";   $counter ++;   //get a cumulative value of the price as items are added to the basket and multiply by quantity as we go.   $price = $price + (calcVAT (htmlspecialchars($row['Price_ExVat']))) * htmlspecialchars($row['quantity']);  } //assign subtotal and round to 2 decimal places $subtotal = $price; $total = $subtotal + $postagerate; //pick overall postage type if ($postagerate == 5) $postage = 3; else if ($postagerate == 9) $postage = 2; else if ($postagerate == 10) $postage = 1; } //update shopper table with new/changed info $sqlshopper = "SELECT * FROM shopper WHERE User_ID = '" . $userID . "'"; //echo "query: " . $sqlshopper; $result = mysql_query($sqlshopper); $rowCount2 = mysql_num_rows($result); //add shopper if ($rowCount2 == 0) { $sqladd = "INSERT INTO shopper" . $shopperFields . "VALUES ('" . $userID . "', '" . $total . "', '" . $postage . "')"; //echo "noshopper: " . $sqladd; $shopadd = mysql_query($sqladd); if (!$shopadd) echo "<font class=error><p>Your basket has not been processed</p></font>"; } else { //update details $sqlupdate = "UPDATE shopper SET Basket_total = '" . $total . "', Postage = '" . $postage . "' WHERE user_ID = '" . $userID . "'"; //echo "shopper: " . $sqlupdate; $shopupdate = mysql_query($sqlupdate); if (!$shopupdate) echo "<font class=error><p>Your basket has not been updated</p></font>"; } // finish table
    

  13. Hi, 

    Please can someone point me in the right direction to solving this.

     

    The following code set the postage rate on a basket.  It selects the lowest postage assigned to a product and set that as the postage rate.

     

    I now need this to work the opposite way round and select the highest postage rate of the added products.

     

    The postage rates are stored in the database as:

     

    0=0.00

    1=4.95

    2=7.95

    3=12.95

     

    So it looks like somewhere there has been something added that tells it to always give preference to the "0" of any products giving the lowest postage but I'm sure on this....

     

     

    Thanks.

     

    //set default postage value outside loop$postagerate = 15.00; while ($row = mysql_fetch_assoc($result)){  //decide which postage value is the highest and use that to calculate overall price  //get the postage values for each product  $sqlpostquery = "SELECT * FROM postage WHERE Post_ID = '" . htmlspecialchars($row['Post_ID']) . "'";   //get the postage values from the database  $postresult = mysql_query($sqlpostquery);  $rowpost = mysql_fetch_assoc($postresult);   // check if postage value was available  if ($postresult || !(mysql_num_rows($postresult) == 0))    {    $rawpostage = htmlspecialchars($rowpost['Post_Cost']) ? htmlspecialchars($rowpost['Post_Cost']) : 0.00;     //get the lowest postage rate.    if ($postagerate > $rawpostage)      {        $postagerate = $rawpostage;    }  }  else  {    $postagerage = 0.00;  }   //round postage rate of 2 decimal places  $postagerate = $postagerate;   //release the postage resultset array 
      mysql_free_result($postresult);
    

  14. Hi,

     

    I have a section of code that sends an order confirmation to me when a customer places an order with us.

     

    This all works fine but recently, I have started to get duplicate confirmations coming from the same customers, one in particular, many times a day...

     

    Is there anything obvious about this code that could be causing it?

     

    Thanks,

     

    <?php //get info from shopper table$sqlquery = "SELECT * FROM shopper WHERE user_ID = '" . $userID . "'";$result = mysql_query($sqlquery);$rowCount = mysql_num_rows($result); // if no matches then nothing to checkoutif ($rowCount == 0){echo ("<p><font class=error>Your basket was empty. You have come to this page in error!!<br>Please return to the main site</font></p>");return;}else{ //store shopper details$shoprow = mysql_fetch_assoc($result);$Basket_total = number_format(htmlspecialchars($shoprow['Basket_total']), 2);$Post_type = htmlspecialchars($shoprow['Postage']);$Postage = htmlspecialchars($shoprow['Postage']);$custdetails = explode("\n",$shoprow["Customer_Address"]);foreach($custdetails as $value) {if(strpos($value,"Customer_Name") !== false) { $Additional_Details .= "$value\n"; }if(strpos($value,"Customer_Surname") !== false) { $Additional_Details .= "$value\n"; }if(strpos($value,"Business_name") !== false) { $Additional_Details .= "$value\n"; }}//get basket details$sqlquery = "SELECT * FROM basket WHERE userID = '" . $userID . "'";$result = mysql_query($sqlquery);$rowCount = mysql_num_rows($result);if ($rowCount == 0){echo "<font class=error><p>Error: Your basket was empty.</p></font>";return;}else{// select the userID's basket query and the Product Reference relating to each of the basket's productID's$sqlquery = "SELECT * FROM basket INNER JOIN products ON basket.productID = products.Prod_ID WHERE ((basket.userID) = '" . $userID . "')";//echo $sqlquery;$baskresult = mysql_query($sqlquery);$rowCount = mysql_num_rows($baskresult); //set counter to name each hidden form element for the product details$frmCount = 1; $strBody = "Order Details are as follows\n\n";$strBody = $strBody . "ShopperID : ".$shopperID."\n\n";$strBody = $shoprow["Customer_Address"]."\n\n";//get alternate delivery details$strBody = $shoprow["Delivery_Address"]."\n\n";$strBody = $shoprow["Search_Engine"]."\n\n";while ($row = mysql_fetch_assoc($baskresult)){ //cut the prod_type variable//get the length of the variable$strLength = strlen ($row["Prod_Type"]);//assign first 2 characters of variable$strPrefix = substr($row["Prod_Type"], 0, 2);//debug//echo "\n prefix :" . $strPrefix;//assign remaining characters of variable$strSuffix = substr($row["Prod_Type"], 2, $strLength);//debug//echo "\n suffix :" . $strSuffix;   //set product header image depending on the Prod_Type Code//start the table row$strProdType = prodType ($strPrefix); $strBody = $strBody ."Order : ".$frmCount;$strBody = $strBody ."\nCarmake : ".htmlspecialchars($row['Car_Make']);$strBody = $strBody ."\nProduct Type : ".$strProdType;$strBody = $strBody ."\nProduct Make : ".htmlspecialchars($row['Prod_Make']);$strBody = $strBody ."\nProduct Description : ".htmlspecialchars($row['Product_Desc']);$strBody = $strBody ."\nProduct reference : ".htmlspecialchars($row['Prod_REF']);$strBody = $strBody ."\nQuantity : ".htmlspecialchars($row['quantity']);$strBody = $strBody ."\nProduct Price : ".number_format(calcVAT(htmlspecialchars($row['Price_ExVat'])), 2);$strBody = $strBody ."\n"."End of order ".$frmCount."\n\n";$frmCount ++; }//end while $strBody = $strBody .$Additional_Details."\n\n";$strBody = $strBody ."Postage rate is ".$Postage."\n";$strBody = $strBody ."\n\nTotal : ".$currency . $Basket_total; }//end else}//end else   // set up mail details$mail_to = "info@mydomain.com";//info@mydomain.com$mail_from = stripslashes($Customer_Email);$mail_subject = "Order Confirmation";$mail_headers = "FROM: $mail_from\r\n";//added additional recipient$mail_body = $strBody;   //create mail footer message$mail_footer = "\n\nText here"; //concatinate mail_body and mail_footer$mail_body = $mail_body . $mail_footer;// send mailif (mail($mail_to, $mail_subject, $mail_body, $mail_headers)) {//echo ("<p>Message sent</p>");} else {echo ("<p>Error On Sending Mail</p>");}?>
    

  15. Ah!  a case of seeing wood for the trees!  I hadn't realised that I has not changed that line to "Delivery_Address"  !

     

     

     

     Honestly I don't know why you even did this

    Desperation I think....  I was trying anything to make this work!

     

    It now prints correctly in 2 paragraphs as I want it but the delivery address section is still repeating itself 11 times??

  16. OK. Viewing the source of this appears as it should.  I't seems just the email body is incorrect.

    
    
    Array   (   [user_ID] => 26fd3a48dcf0f5565b81730fe9177e47   [basket_total] => 92.90   [Postage] => 0   [CardRef] =>   [Customer_Address] => Customer_Name = JOHN   Customer_Surname = SMITH   Business_name = SMITH & CO   Customer_Address1 = 25 ORCHARD STREET   Customer_Address2 = LITTLE VILLAGE   Customer_Town = LONDON   Customer_County = Bucks   Customer_Postcode = NE21 9RE   Customer_Email = J@JOHN.COM   Customer_Tel = 123456   Customer_Mobile = 123456   [Delivery_Address] => Delivery_Title = Mr.   Delivery_Firstname = George   Delivery_Surname = JONES   Delivery_Businessname = SMITH & CO   Delivery_Address1 = 123 HIGH STREET   Delivery_Address2 = HACKNEY   Delivery_Town = LONDON   Delivery_County = BUCKS   Delivery_Postcode = NE10 7FD   [search_Engine] =>   [success] =>   [shopping_Basket] =>   Car1_Make = n/a   Car1_Model = not specific   Product1_Make = Thule   Product1_Model = 591   Product1_Type = Bike Rack   Product1_REF = 591   Product1_Quantity = 1   Product1_Price = 84.95       )
×
×
  • 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.