Zen Cart 1.5.4
Fresh install – no upgrades
No plugins/addons
PHP Version 5.4.40
MySQL 5.5.42-37.1
One-click install from Bluehost where the cart is hosted
Researched FAQ and searched forum
In the past few years I have created several custom farm applications using Zen Cart where I clone the “storepickup” shipping module to display multiple Buying Club location options during checkout. With as many as 50 locations per farm with frequent changes to addresses, I made the pages dynamic and linked to a table named “location” so that I wouldn't have to hand code all the changes.
This has worked quite well until a few months ago when I found that I have to make a direct connection to the database from within the cloned page code or would get a failure to connect database error within the Zen Cart Admin shipping page. I am guessing this change is related to some security upgrades in recent versions of Zen Cart.
Anyway I added the connection code and it works, but takes extra time to configure and probably unnecessary. Of course I want to be sure to avoid sql injection.
Here is the page code for one of the clones that worked well previously:
PHP Code:
$query = "SELECT title FROM location WHERE id=11";
$mysql_result = @ mysql_query ($query)
or die ("Query '$query' failed with error message: \"" . mysql_error () . '"');
$row = @ mysql_fetch_row ($mysql_result)
or die ("Try a different query - this one did not return any rows.");
$title=$row[0];
$query2 = "SELECT text FROM location WHERE id=11";
$mysql_result2 = @ mysql_query ($query2)
or die ("Query '$query' failed with error message: \"" . mysql_error () . '"');
$row2 = @ mysql_fetch_row ($mysql_result2)
or die ("Try a different query - this one did not return any rows.");
$text=$row2[0];
define('MODULE_SHIPPING_LOCATION11PICKUP_TEXT_TITLE', $title);
define('MODULE_SHIPPING_LOCATION11PICKUP_TEXT_DESCRIPTION', 'Delivery Location');
define('MODULE_SHIPPING_LOCATION11PICKUP_TEXT_WAY', $text);
Now, to avoid coding a special mysql connection, I am trying things like:
Code:
$query = $db->Execute("SELECT title FROM location WHERE id=10");
No error, but no data displayed on the admin shipping page.
Any thoughts or suggestions on how to get this to work and make sure it is secure would be appreciated. Thanks in advance for any help provided. Dave