How Can I Display Prices On Static Web Pages?

Please check here first before posting a question. We will update this forum on a regular basis with tips and how-tos.

Moderator: frankjan

Post Reply
Site Admin
Posts: 392
Joined: May 03, 2004 8:57 pm

How Can I Display Prices On Static Web Pages?

Post by frankjan » Nov 22, 2008 1:46 pm

Here's some PHP code to allow you to display pricing from your SurfShopPRO MySQL db on your static web pages.

1] First you need a password file on your server. You can place it anywhere you like, but try to save it above your public directory for added security. Here's what the password file should contain:

Code: Select all

$host = "localhost"; 
$user = "user_name"; 
$pass = "password"; 
$dbname = "db_name";
$db = mysql_connect($host,$user,$pass) or die (mysql_errno().": ".mysql_error()."<br />"); 
Replace user_name and password with your personal information. It's always best to create another username for this application and only give that user access to SELECT statements. Anything more can be a security risk.

2] Then place the following line in the <head></head> section of your web page:

Code: Select all

<?php @include_once("/path/to/your/password/file.php"); ?>
The @ symbol will suppress any errors from being displayed on your web page, which would show the path to your password file.

3] In the body of your page, insert:

Code: Select all

<?php $result = mysql_query("SELECT unitprice FROM catalog WHERE itemid='ITEM#'",$db);
printf("<b><font color=\"#555555\">Your Price:</font> $%s</b><br />\n", money_format('%i', mysql_result($result,0,"unitprice"))); ?>
4] To display an Add To Cart button on a static page, add a form like this:

Code: Select all

<form action="/cgi-bin/surfshop/shop.cgi" method="get">
  <input type="image" src="/path/to/image.png" name="addToCartButton" alt="Add To Cart" />
  <input type="hidden" name="itemid" value="ITEM#" />
  <input type="text" name="i_ITEM#" value="1" size="4" />
  <input type="hidden" name="c" value="viewcart.htm" />
In the above examples, ITEM# should be replaced with an actual item # from your MySQL db.
Frank Jance
SurfShop Forum Admin

Setting Up Shop Has Never Been Easier!

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest