Jump to content

ohno

Members
  • Content Count

    38
  • Joined

  • Last visited

Community Reputation

1 Neutral

About ohno

  • Rank
    Member
  1. I use this script to detect a browser IP, however it doesn't work with IPv6. http://phptutorial.info/iptocountry/the_script.html Any ideas what is required to make it work with both IPv4 & IPv6? Thanks
  2. I backed up the DB and changed them so they are all utf8mb4_unicode_ci. I also changed this line :- if (!$this->db->set_charset("utf8")) { to this :- if (!$this->db->set_charset("utf8mb4")) { And it seems to have fixed the fault Thanks for your help.
  3. OK, this is how it looks now:- class DbManager { public $db; function __construct() { mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); $this->db = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_DATABASE); if ($this->db->connect_errno) { die("Failed to connect to MySQL: (" . $this->db->connect_errno . ") " . $this->db->connect_error); } if (!$this->db->set_charset("utf8")) { die("Error loading character set utf8: " . $this->db->error); } else { } } The error log now gives this :- Uncaught mysqli_sql_exception: Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation 'like' in /home/website/public_html/include/database.php:30 Looking at the DB it seems some columns have collation set to utf8mb4_unicode_ci while others are latin1_swedish_ci! I guess I just need to change the collation of those so they are all utf8mb4_unicode_ci?
  4. I don't see mysqli_connect() :- class DbManager { public $db; function __construct() { $this->db = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_DATABASE); if ($this->db->connect_errno) { die("Failed to connect to MySQL: (" . $this->db->connect_errno . ") " . $this->db->connect_error); } if (!$this->db->set_charset("utf8")) { die("Error loading character set utf8: " . $this->db->error); } else { } }
  5. Hi everyone, Happy New Year in advance! I have the following error occurring :- PHP Fatal error: Uncaught Error: Call to a member function fetch_assoc() on bool in /home/website/public_html/include/database.php:31 Line 31 :- while ($row = $query_result->fetch_assoc()) { $result[] = $row; } Which is in this query :- public function DbGetAll($queryString) { $query_result = $this->db->query($queryString); $result = array(); while ($row = $query_result->fetch_assoc()) { $result[] = $row; } return $result; } I'm guessing it's a problem with the sql query but I'm not sure how to fix? The error log also references this file :- #0 /home/website/public_html/data_objects/do_catalogue.php(68): DbManager->DbGetAll('SELECT p.code, ...') #1 /home/website/public_html/smarty_plugins/function.load_search.php(38): DoCatalogue->SearchProducts(Array) #2 /home/website/public_html/smarty_plugins/function.load_search.php(5): Search->init() But I ***think*** that is just because the above query is incorrect? Thank you for any help in fixing this error.
  6. As above, the script came with a file "unknown.php" which is just empty, I can't see how the code would ever use the file as I can't see it referenced in the code anywhere? What I did was modify "countries.php" by adding this code :- "UNKNOWN" => array("Undeclared","an undeclared location"), It all works as it should, if the IP is from an unknown location the text I added to countries.php is displayed. It just seems odd the original author had "unknown.php"? Thanks
  7. Anyone? Here's the original authors site again :- http://phptutorial.info/iptocountry/the_script.html
  8. Fixed I was on the right tracks but had put the code in the wrong place, oops. Anyway, many thanks for helping to sort it. On a side note the script came with a file "unknown.php" which is just empty, I can't see how the code would ever use the file as I can't see it referenced in the code anywhere? Anyway, what I did was modify "countries.php" by adding this code :- "UNKNOWN" => array("Undeclared","an undeclared location"), It all works as it should, if the IP is from an unknown location the text added to countries.php is displayed. It just seems odd the original author had "unknown.php"? Thanks again for your valued help
  9. Thanks. I'll give that a go in the morning
  10. Hi guys, hope someone can help? I noticed an error in my logs & upon digging it seems this script is causing the issue:- <?php error_reporting(E_ALL); //$IPaddress=$_SERVER['REMOTE_ADDR']; $IPaddress='45.152.180.38'; $two_letter_country_code=iptocountry($IPaddress); include("ip_files/countries.php"); $three_letter_country_code=$countries[ $two_letter_country_code][0]; $country_name=$countries[$two_letter_country_code][1]; print "Two letters code: $two_letter_country_code<br>"; print "Three letters code: $three_letter_country_code<br>"; print "Country name: $country_name<br>"; // To display flag $file_to_check="flags/$two_letter_country_code.gif"; if (file_exists($file_to_check)){ print "<img src=$file_to_check width=30 height=15><br>"; }else{ print "<img src=flags/noflag.gif width=30 height=15><br>"; } function iptocountry($ip) { $numbers = preg_split( "/\./", $ip); include("ip_files/".$numbers[0].".php"); $code=($numbers[0] * 16777216) + ($numbers[1] * 65536) + ($numbers[2] * 256) + ($numbers[3]); foreach($ranges as $key => $value){ if($key<=$code){ if($ranges[$key][0]>=$code){$two_letter_country_code=$ranges[$key][1];break;} } } if ($two_letter_country_code==""){$two_letter_country_code="UNKNOWN";} return $two_letter_country_code; } ?> This script was originally from here http://phptutorial.info/iptocountry/the_script.html The error I'm getting is :- [28-Nov-2019 16:57:56 UTC] PHP Notice: Undefined variable: two_letter_country_code in /home/drgl1966/testing.site/testinguser/test.php on line 35 I'm ***guessing*** this may be caused by my newer version of PHP (7.3, although I must admit I didn't look at old logs to see if the problem exists with older PHP version). I hard coded the made up IP in the code above as the problem only happens if the IP address is not known. Any idea's how to fix? As you can probably gather I'm not a PHP coder! I've searched online for answers but all the things I've found & tried have failed Thanks in advance for any help with this...
  11. Excuse my ignorance but what is "PDO"? Can someone who works with PHP update this code so it will all work with the newer versions of PHP? Will we HAVE to upgrade to newer versions of PHP? Thanks
  12. //Add to cart, view cart, cart summary, xselling all in one enhancement. Requires product ID $sql = "SELECT code FROM products WHERE productid='".mysql_real_escape_string($_GET['id'])."'"; $result = mysql_query($sql); while ( $row = @mysql_fetch_array($result, MYSQL_BOTH) ) { $prodcode = $row['code']; } $data = '<table border="0"><tr><td colspan="2"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"color="#000000"><form method="post" action="https://www.domain.com/s_addtocart.php" target="_blank"><input type="hidden" name="code" value="'.$prodcode.'" /><input type="image" src="images/add.png" name="Submit" alt="Add To Cart" style="vertical-align:middle; border: none;" hspace="2" /> Quantity: <input type="text" name="quantity" size="3" value="1" /></form></font></td></tr><tr><td><font size="2" face="Verdana, Arial, Helvetica, sans-serif"color="#000000"><a href="https://www.domain.com/cart.php" target="_blank"><img src="images/viewcart.png" alt="View Cart" border="0px" style="vertical-align:middle" hspace="2" /></a></font></td><td>'; $data .= '<font size="2" face="Verdana, Arial, Helvetica, sans-serif"color="#000000">'; if ( !(isset($_SESSION['cartid'])) || ($_SESSION['cartid'] == "") ) //if ( (!isset($_COOKIE['RITD_Cart_ID'])) || ($_COOKIE['RITD_Cart_ID'] == '') ) { $data .= 'No items have been added to the cart yet.'; } else { $sql = "SELECT sub FROM carts WHERE cartid='".$_SESSION['cartid']."'"; //$sql = "SELECT orderno, sub FROM carts WHERE cartid='".$_COOKIE['RITD_Cart_ID']."'"; $result = mysql_query($sql); while ( $row = @mysql_fetch_array($result, MYSQL_BOTH) ) { if ( $row['sub'] == "" ) { $row['sub'] = "0.00"; } $orderno = $orderpre . ($orderstart+$_SESSION['cartid']); $data .= 'Order Number: '.$orderno.' with Sub-Total: £'.$row['sub']; $data = str_replace("&", "&", $data); } } $data .= '</font></td></tr></table>'; break; I should add, I know NOTHING about PHP! This was written for me about 7 years ago. It all works I'm just trying to modify that one section. I've since worked out that it is just this section of code that needs modifying.
  13. I've posted on here in the past & had great help so I'm hoping someone can help again Basically what I was trying to do was make the add to cart button grey out and lose the add function if a product is marked as not available in the back end. I found this block of code :- //Displays the add to cart form. Requires product ID $sql = "SELECT code FROM products WHERE productid='".mysql_real_escape_string($_GET['id'])."'"; $result = mysql_query($sql); while ( $row = @mysql_fetch_array($result, MYSQL_BOTH) ) { $data = '<font size="2" face="Verdana, Arial, Helvetica, sans-serif"color="#000000"><form method="post" action="https://www.domain.com/s_addtocart.php" target="_blank"><input type="hidden" name="code" value="'.$row['code'].'" /><input type="image" src="images/add.png" name="Submit" alt="Add To Cart" style="vertical-align:middle; border: none;" />Quantity: <input type="text" name="quantity" size="3" value="1" /></form></font>'; } break; which i then modified as follows & it all works as it should :- //Displays the add to cart form. Requires product ID $sql = "SELECT available, due, code FROM products WHERE productid='".mysql_real_escape_string($_GET['id'])."'"; $result = mysql_query($sql); while ( $row = @mysql_fetch_array($result, MYSQL_BOTH) ) { if ( $row['available'] == '1' ) { $data = '<font size="2" face="Verdana, Arial, Helvetica, sans-serif"color="#000000"><form method="post" action="https://www.domain.com/s_addtocart.php" target="_blank"><input type="hidden" name="code" value="'.$row['code'].'" /><input type="image" src="images/add.png" hspace="5" name="Submit" alt="Add To Cart" style="vertical-align:middle; border: none;" />Quantity: <input type="text" name="quantity" size="3" value="1" /></form></font>'; } elseif ( $row['available'] == '0' ) { $data .= ' <img src="images/addtocartoutofstock.png" width="278" height="39" alt="Sorry, currently out of stock" width="23" height="20"><font color="#C70000" font size="3"><strong>OUT OF STOCK</strong></font><img src="images/outofstock.png" width="23" height="20"> <font size="2" face="Geneva, Arial, Helvetica, sans-serif" color="#000000">'.$row['due']; } } break; So what's the problem? Well, the actual code that is in use for the add to cart buttons actually has view cart, cross selling & cart summary in the code here is the code in use :- //Add to cart, view cart, cart summary, xselling all in one enhancement. Requires product ID $sql = "SELECT code FROM products WHERE productid='".mysql_real_escape_string($_GET['id'])."'"; $result = mysql_query($sql); while ( $row = @mysql_fetch_array($result, MYSQL_BOTH) ) { $prodcode = $row['code']; } $data = '<table border="0"><tr><td colspan="2"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"color="#000000"><form method="post" action="https://www.domain.com/s_addtocart.php" target="_blank"><input type="hidden" name="code" value="'.$prodcode.'" /><input type="image" src="images/add.png" name="Submit" alt="Add To Cart" style="vertical-align:middle; border: none;" hspace="2" /> Quantity: <input type="text" name="quantity" size="3" value="1" /></form></font></td></tr><tr><td><font size="2" face="Verdana, Arial, Helvetica, sans-serif"color="#000000"><a href="https://www.domain.com/cart.php" target="_blank"><img src="images/viewcart.png" alt="View Cart" border="0px" style="vertical-align:middle" hspace="2" /></a></font></td><td>'; $data .= '<font size="2" face="Verdana, Arial, Helvetica, sans-serif"color="#000000">'; if ( !(isset($_SESSION['cartid'])) || ($_SESSION['cartid'] == "") ) //if ( (!isset($_COOKIE['RITD_Cart_ID'])) || ($_COOKIE['RITD_Cart_ID'] == '') ) { $data .= 'No items have been added to the cart yet.'; } else { $sql = "SELECT sub FROM carts WHERE cartid='".$_SESSION['cartid']."'"; //$sql = "SELECT orderno, sub FROM carts WHERE cartid='".$_COOKIE['RITD_Cart_ID']."'"; $result = mysql_query($sql); while ( $row = @mysql_fetch_array($result, MYSQL_BOTH) ) { if ( $row['sub'] == "" ) { $row['sub'] = "0.00"; } $orderno = $orderpre . ($orderstart+$_SESSION['cartid']); $data .= 'Order Number: '.$orderno.' with Sub-Total: £'.$row['sub']; $data = str_replace("&", "&", $data); } } $data .= '</font></td></tr></table>'; $xprods = array(); $sql = "SELECT xselling.xproductid FROM xselling, products WHERE xselling.xproductid=products.productid AND xselling.active='1' AND products.active='1' AND products.live='1' AND xselling.productid='".mysql_real_escape_string($_GET['id'])."'"; //$data .= $sql; $result = mysql_query($sql); while ( $row = @mysql_fetch_array($result, MYSQL_BOTH) ) { array_push($xprods, $row['xproductid']); } if ( (count($xprods) <= 4) && (count($xprods) > 0) ) { $a = 0; $b = count($xprods); while ( $a < $b ) { $sql = "SELECT code, title, img, url, price FROM products WHERE active='1' AND live='1' AND productid='".$xprods[$a]."'"; $result = mysql_query($sql); switch ($a) { case 0: $row = mysql_fetch_assoc($result); $x1 = '<a href="'.$producturl.$row['url'].'" style="color:#0000FF;"><img src="'.$imageurl.$row['img'].'" border="none" alt="'.$row['title'].'" /><br />'.$row['title'].'</a>'; $x1a = '£'.$row['price']; $x1b = '<form method="post" action="https://www.domain.com/s_quickadd.php" target="_blank"><input type="hidden" name="code" value="'.$row['code'].'" /><input type="image" src="images/add.png" name="Submit" alt="Add To Cart" /></form>'; break; case 1: $row = mysql_fetch_assoc($result); $x2 = '<a href="'.$producturl.$row['url'].'" style="color:#0000FF;"><img src="'.$imageurl.$row['img'].'" border="none" alt="'.$row['title'].'" /><br />'.$row['title'].'</a>'; $x2a = '£'.$row['price']; $x2b = '<form method="post" action="https://www.domain.com/s_quickadd.php" target="_blank"><input type="hidden" name="code" value="'.$row['code'].'" /><input type="image" src="images/add.png" name="Submit" alt="Add To Cart" /></form>'; break; case 2: $row = mysql_fetch_assoc($result); $x3 = '<a href="'.$producturl.$row['url'].'" style="color:#0000FF;"><img src="'.$imageurl.$row['img'].'" border="none" alt="'.$row['title'].'" /><br />'.$row['title'].'</a>'; $x3a = '£'.$row['price']; $x3b = '<form method="post" action="https://www.domain.com/s_quickadd.php" target="_blank"><input type="hidden" name="code" value="'.$row['code'].'" /><input type="image" src="images/add.png" name="Submit" alt="Add To Cart" /></form>'; break; case 3: $row = mysql_fetch_assoc($result); $x4 = '<a href="'.$producturl.$row['url'].'" style="color:#0000FF;"><img src="'.$imageurl.$row['img'].'" border="none" alt="'.$row['title'].'" /><br />'.$row['title'].'</a>'; $x4a = '£'.$row['price']; $x4b = '<form method="post" action="https://www.domain.com/s_quickadd.php" target="_blank"><input type="hidden" name="code" value="'.$row['code'].'" /><input type="image" src="images/add.png" name="Submit" alt="Add To Cart" /></form>'; break; } $a++; } } elseif ( count($xprods) > 4 ) { $c = 0; while ( $c < 4 ) { $pick = rand(1,count($xprods)); $pick = $pick - 1; switch ($c) { case 0: $x1 = $xprods[$pick]; break; case 1: $x2 = $xprods[$pick]; break; case 2: $x3 = $xprods[$pick]; break; case 3: $x4 = $xprods[$pick]; break; } unset($xprods[$pick]); $xprods = array_values($xprods); $c++; } $sql = "SELECT code, title, img, url, price FROM products WHERE active='1' AND live='1' AND productid='".$x1."'"; $result = mysql_query($sql); while ( $row = @mysql_fetch_array($result, MYSQL_BOTH) ) { $x1 = '<a href="'.$producturl.$row['url'].'" style="color:#0000FF;"><img src="'.$imageurl.$row['img'].'" border="none" alt="'.$row['title'].'" /><br />'.$row['title'].'</a>'; $x1a = '£'.$row['price']; $x1b = '<form method="post" action="https://www.domain.com/s_quickadd.php" target="_blank"><input type="hidden" name="code" value="'.$row['code'].'" /><input type="image" src="images/add.png" name="Submit" alt="Add To Cart" /></form>'; } $sql = "SELECT code, title, img, url, price FROM products WHERE active='1' AND live='1' AND productid='".$x2."'"; $result = mysql_query($sql); while ( $row = @mysql_fetch_array($result, MYSQL_BOTH) ) { $x2 = '<a href="'.$producturl.$row['url'].'" style="color:#0000FF;"><img src="'.$imageurl.$row['img'].'" border="none" alt="'.$row['title'].'" /><br />'.$row['title'].'</a>'; $x2a = '£'.$row['price']; $x2b = '<form method="post" action="https://www.domain.com/s_quickadd.php" target="_blank"><input type="hidden" name="code" value="'.$row['code'].'" /><input type="image" src="images/add.png" name="Submit" alt="Add To Cart" /></form>'; } $sql = "SELECT code, title, img, url, price FROM products WHERE active='1' AND live='1' AND productid='".$x3."'"; $result = mysql_query($sql); while ( $row = @mysql_fetch_array($result, MYSQL_BOTH) ) { $x3 = '<a href="'.$producturl.$row['url'].'" style="color:#0000FF;"><img src="'.$imageurl.$row['img'].'" border="none" alt="'.$row['title'].'" /><br />'.$row['title'].'</a>'; $x3a = '£'.$row['price']; $x3b = '<form method="post" action="https://www.domain.com/s_quickadd.php" target="_blank"><input type="hidden" name="code" value="'.$row['code'].'" /><input type="image" src="images/add.png" name="Submit" alt="Add To Cart" /></form>'; } $sql = "SELECT code, title, img, url, price FROM products WHERE active='1' AND live='1' AND productid='".$x4."'"; $result = mysql_query($sql); while ( $row = @mysql_fetch_array($result, MYSQL_BOTH) ) { $x4 = '<a href="'.$producturl.$row['url'].'" style="color:#0000FF;"><img src="'.$imageurl.$row['img'].'" border="none" alt="'.$row['title'].'" /><br />'.$row['title'].'</a>'; $x4a = '£'.$row['price']; $x4b = '<form method="post" action="https://www.domain.com/s_quickadd.php" target="_blank"><input type="hidden" name="code" value="'.$row['code'].'" /><input type="image" src="images/add.png" name="Submit" alt="Add To Cart" /></form>'; } } $data .= ' </font> <table border="0" width="600px"> <tr style="background-color: #2658C8; color:#FFFFFF; font-weight: bold; font-size: 15px; font-family:Verdana, Arial, Helvetica, sans-serif;"> <td colspan="4">You may also be interested in these products...</td> </tr> <tr> <td align="center" style="vertical-align:top; font-size: 12px; font-family:Verdana, Arial, Helvetica, sans-serif;">'.$x1.'</td> <td align="center" style="vertical-align:top; font-size: 12px; font-family:Verdana, Arial, Helvetica, sans-serif;">'.$x2.'</td> <td align="center" style="vertical-align:top; font-size: 12px; font-family:Verdana, Arial, Helvetica, sans-serif;">'.$x3.'</td> <td align="center" style="vertical-align:top; font-size: 12px; font-family:Verdana, Arial, Helvetica, sans-serif;">'.$x4.'</td> </tr> <tr> <td align="center" style="font-size: 12px; font-family:Verdana, Arial, Helvetica, sans-serif;">'.$x1a.'</td> <td align="center" style="font-size: 12px; font-family:Verdana, Arial, Helvetica, sans-serif;">'.$x2a.'</td> <td align="center" style="font-size: 12px; font-family:Verdana, Arial, Helvetica, sans-serif;">'.$x3a.'</td> <td align="center" style="font-size: 12px; font-family:Verdana, Arial, Helvetica, sans-serif;">'.$x4a.'</td> </tr> <tr> <td align="center" style="font-size: 12px; font-family:Verdana, Arial, Helvetica, sans-serif;">'.$x1b.'</td> <td align="center" style="font-size: 12px; font-family:Verdana, Arial, Helvetica, sans-serif;">'.$x2b.'</td> <td align="center" style="font-size: 12px; font-family:Verdana, Arial, Helvetica, sans-serif;">'.$x3b.'</td> <td align="center" style="font-size: 12px; font-family:Verdana, Arial, Helvetica, sans-serif;">'.$x4b.'</td> </tr> </table> '; break; I'd like to get that code to work in the same way, ie, if the back end DB has the not available flag set to yes the add to cart button is replaced as in my second code snippet. Hope someone can help! Thanks
  14. I don't know, I didn't write any of this code nor am I a programmer! I'm just trying to fix the mess I've been left with.
  15. You sir are a genius! It now passes the correct amount, will that line of code only affect the $centinel_total string? The tax amount isn't used by them but their logs show an incorrect amount there too, would I just add the same sort of thing above the $centinel_vatamont string?
×
×
  • 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.