can your wampserver run these script without error?
Posted by: joseph (60.51.135.---)
Date: February 15, 2006 09:50AM

I have tried to run below php file, but get errors...
Try run in your wampsever...maybe my wampserver php.ini and config.inc got something missing....

phpCart Installation Instructions

1. Create New MySQL Database. Insert code below into SQL query. Some hosts only allow one database so if you get an error skip to stage 2.

CREATE DATABASE `phpcart`;

2. Create Table. Insert code below into SQL query.

CREATE TABLE `phpcart_products` (
`id` int(11) NOT NULL auto_increment,
`product` text NOT NULL,
`price` decimal(5,2) NOT NULL default '0.00',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ;

3. Now add some products to your table. You'll have to do this from you mysql admin page for now until I build a admin section.

4. Edit functions_cart.php with your mysql details

5. Upload phpCart files to server

6. Go to phpCart_shop.php and your products will be there.

Other Options

5. Include the minibasket in your pages.

<? include "phpCart_minibasket.php"; ?>

6. Link to shopping basket.

<a href="phpCart_basket.php">View Cart / Checkout</a>
---------------------------------------------------------------------------------------------------

the codes are:

(Functions_cart.php)
<?
$mysql_server = "localhost";
$mysql_username = "root";
$mysql_pwd = "admin";
$mysql_dbname = "phpcart";
$mysql_tablename = "phpcart_products";

$cur_symbol = "US";

// database connect function
function db_connect () {

global $mysql_server, $mysql_username, $mysql_pwd, $mysql_dbname;

$db = mysql_connect($mysql_server, $mysql_username, $mysql_pwd, false, 128) or die("Problem connecting"winking smiley;
mysql_select_db($mysql_dbname,$db) or die("Problem selecting database"winking smiley;

}

// generate random string for cookie and session
function setstp () {

settype($str,"string"winking smiley;

// generate random number
for ($i=0;$i<20;$i++) {

$str .= chr (rand (1, 255));

}

// encode string to 40 characters.
$sha = sha1 ($str);
// set cookie with value and set session with the same value.
setcookie ("SESSSEC", $sha, NULL);
$_SESSION["CookieChk"]['SESSSEC'] = $sha;

}

// add item to cart
function add_item_to_cart($id,$quantity) {

// set cookie and store value in session
setstp();

// call database connect function
db_connect();
// get product id from database
global $mysql_tablename;
$sel_products = mysql_query("SELECT * FROM $mysql_tablename WHERE id=".$id.""winking smiley;
$item = mysql_fetch_array($sel_products);
// returns the number of rows in a result, if 1 item exists if 0 item doesn't exists.
$num_rows = mysql_num_rows($sel_products);

// if item exists then add item to cart
if ($num_rows >= 1) {

session_regenerate_id(TRUE);

$_SESSION["cart"][$id][0] = $item["id"];
$_SESSION["cart"][$id][1] = $quantity;

header ("location:".$_SERVER['HTTP_REFERER']);

}
}

// check cookie and session and then show cart
function validate() {

if (!isset($_COOKIE['SESSSEC'])) {
$valid = FALSE;
// probable attempt at Session Fixation, you should probably log this
} elseif (!isset($_SESSION["CookieChk"]['SESSSEC'])) {
$valid = FALSE;
// umm, this shouldn't occur, but yeah, do whatever you want, maybe log an error or something, probably not needed except to notice bugs in your app....
} elseif ($_COOKIE["SESSSEC"] == $_SESSION["CookieChk"]['SESSSEC']) {
$valid = TRUE;
setstp();
} else {
$valid = FALSE;
// very Proably attempt at session hijacking, because while both items exist they don't match, definately log this
}
return $valid;
}


// delete item from cart
function del_item($id) {

// call database connect function
db_connect();
global $mysql_tablename;
$sel_products = mysql_query("SELECT * FROM $mysql_tablename WHERE id=".$id.""winking smiley;
$item = mysql_fetch_array($sel_products);

session_start();

// remove item from cart
session_regenerate_id();
unset($_SESSION["cart"][$item["id"]]);

header ("location:".$_SERVER['HTTP_REFERER']);

}

?>

(phpCart_basket.php)
<?
ob_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "[www.w3.org];
<html>
<head>
<title>phpCart</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="phpCart_style.css" rel="stylesheet" type="text/css">
</head>

<body>
<form name="update" method="post" action="phpCart_manage.php">
<table width="100%" border="0" cellspacing="0" cellpadding="5">
<tr bgcolor="#EEEEEE">
<td width="10%" class="bottomline">&nbsp;</td>
<td width="10%" class="bottomline"><strong>Qty</strong></td>
<td width="60%" class="bottomline"><strong>Product</strong></td>
<td width="10%" class="bottomline"><strong>Price</strong></td>
<td width="10%" class="bottomline"><strong>Line Total </strong></td>
</tr>
<?
include "functions_cart.php";
$totalvalue = 0;

session_start();
// If no sessions has been started $_SESSION["cart"] equals null, thus showing the message no items.
if (!isset($_SESSION["cart"])) {
$_SESSION["cart"] = NULL;
}

if (validate() == TRUE && $_SESSION["cart"] != NULL) {

foreach ($_SESSION["cart"] as $key => $session_data) {

list($ses_id, $ses_quan) = $session_data;

// call database connect function
db_connect();
$sel_products = mysql_query("SELECT * FROM $mysql_tablename WHERE id=".$ses_id.""winking smiley;
$item = mysql_fetch_array($sel_products);

$totalvalue = $totalvalue + ($item["price"]*$ses_quan);
$subtotal = ($item["price"]*$ses_quan);

?>
<tr>
<td class="dividingborder"><a href="<? echo "phpCart_manage.php?act=del&pid=".$ses_id; ?>"><img src="img/icon_del.gif" width="13" height="13" border="0"></a></td>
<td class="dividingborder"><input name="newquan[]" type="text" id="newquan[]3" value="<? echo $ses_quan; ?>" size="5" maxlength="4">
<input name="eid[]" type="hidden" id="eid[]" value="<? echo $ses_id; ?>"></td>
<td class="dividingborder"><? echo $item["product"]; ?></td>
<td class="dividingborder"><? echo $cur_symbol."".number_format($item["price"], 2, '.', ''); ?></td>
<td class="dividingborder"><? echo $cur_symbol."".number_format($subtotal, 2, '.', ''); ?></td>
</tr>
<?
} // end foreach loop

} elseif ($_SESSION["cart"] == NULL) {

echo "<td colspan=\"5\"><center><p>Your basket is currently empty.</p></center></td>";

} else {

echo "<td colspan=\"5\"><center><p>Unknown Error.</p></center></td>";

}
?>
<tr>
<td> <img src="img/icon_del.gif" width="13" height="13"> - delete</td>
<td><? if ($_SESSION["cart"] != NULL) { echo "<input name=\"UpdateChg\" type=\"submit\" id=\"UpdateChg\" value=\"Update\">"; } ?></td>
<td><a href="index.php">Continue Shopping</a></td>
<td><strong>Cart Total</strong></td>
<td><? echo $cur_symbol."".number_format($totalvalue, 2, '.', ''); ?></td>
</tr>
</table>
</form>
</body>
</html>
<?
ob_end_flush();
?>

(phpCart_manage.php)
<?
ob_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "[www.w3.org];
<html>
<head>
<title>phpCart</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="phpCart_style.css" rel="stylesheet" type="text/css">
<?
// UPDATE BASKET QUANTITY
if (isset($_POST["UpdateChg"])) {

session_start();
include "functions_cart.php";

$i = 0;
$size = count($_POST["eid"]);

for ($i = 0; $i <= $size-1; $i++) {

// call remove bad characters function
$badsymbols = array(" ","-","+","*","/","."winking smiley;
$_POST["newquan"][$i] = str_replace($badsymbols,"", $_POST["newquan"][$i]);

if (is_numeric($_POST["newquan"][$i])) {

// if any quantity's equal 0 then remove from cart
if ($_POST["newquan"][$i] == 0) {
unset($_SESSION["cart"][$_POST["eid"][$i]]);
}

// update quantity in cart.
if (array_key_exists($_POST["eid"][$i], $_SESSION["cart"])) {

add_item_to_cart($_POST["eid"][$i], $_POST["newquan"][$i]);

}

} // END IF NUMERIC

}

header ("location:".$_SERVER['HTTP_REFERER']);

} // END BASKET QUANTITY

// TEXT LINKS
if (isset($_GET["act"])) {

// ADD ITEM!
if ($_GET["act"] == "add"winking smiley {

session_start();
include "functions_cart.php";
//unserialize($_SESSION["cart"]);
if (!isset($_SESSION["cart"])) {

// add first item
add_item_to_cart($_GET["pid"],1);

} else if (array_key_exists($_GET["pid"], $_SESSION["cart"])) {

// add 1 to quantity if item in cart already
add_item_to_cart($_GET["pid"],++$_SESSION["cart"][$_GET["pid"]][1]);

} else {

// add any other items after first item
add_item_to_cart($_GET["pid"],1);

}

}


// DELETE ITEM!
if ($_GET["act"] == "del"winking smiley {

include "functions_cart.php";
del_item($_GET["pid"]);

}

} // END ISSET
?>
</body>
</html>
<?
ob_end_flush();
?>

(phpCart_minibasket.php)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "[www.w3.org];
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<table width="100%" border="0" cellpadding="5" cellspacing="0" class="minibasket">
<tr bgcolor="#DDDDDD">
<td><strong>Shopping Basket</strong>
</td>
</tr>
<tr>
<td>
<?

session_start();

// If no sessions has been started $_SESSION["cart"] equals null, thus showing the message no items.
if (!isset($_SESSION["cart"])) {
$_SESSION["cart"] = NULL;
}

$itemcount = count($_SESSION["cart"]);
echo "You have <b>".$itemcount."</b> item(s) in your basket.";

?>
</td>
</tr>
<tr>
<td><a href="phpCart_basket.php">View Cart / Checkout</a></td>
</tr>
</table>
</body>
</html>

(phpCart_shop.php)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "[www.w3.org];
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?
include "functions_cart.php";
db_connect();
$sel_products = mysql_query("SELECT * FROM $mysql_tablename ORDER BY id"winking smiley;
?>
<table width="100%" border="1" cellspacing="0" cellpadding="5">
<tr><td>&nbsp;</td>
<td><strong>Product</strong></td>
<td><strong>Price</strong></td>
</tr>
<?
while ($item = mysql_fetch_array($sel_products)) {
echo "<tr>";
echo "<td><a href=phpCart_manage.php?act=add&pid=".$item["id"].">Add</a></td>";
echo "<td>".$item["product"]."</td>";
echo "<td>".$item["price"]."</td>";
echo "</tr>";
}
?>
</table>
</body>
</html>

(phpCart_style.php)

body {
font-family: Arial, Helvetica, sans-serif;
font-size: small;
}

td {
font-family: Arial, Helvetica, sans-serif;
font-size: small;
}

.bottomline {
border-bottom: 1px solid #DDDDDD;
color:#666666;
}

.dividingborder {
border-bottom: 1px dashed #DDDDDD;
}

.minibasket {
background-color: #EEEEEE;
border: 1px solid #DDDDDD;
}

.minibasketsubtitles {
color:#666666;
font-weight:bold;
}

.minibasket_items {
font-size:x-small;
border-bottom: 1px dashed #DDDDDD;
}
--------------------------------------------

Is anyone could help me to figure out the problems...?

Options: ReplyQuote
Re: can your wampserver run these script without error?
Posted by: CyberSpatium (---.hsd1.or.comcast.net)
Date: February 15, 2006 04:46PM

no one if going to go thought the trouble of insalling this script just to see if it works. let us know what errors you get and most likely we will be able to help you.

Options: ReplyQuote
Re: can your wampserver run these script without error?
Posted by: Scott (---.twcny.res.rr.com)
Date: February 17, 2006 09:50PM

That cart is not done, and there are plenty of errors in the coding. If you really need to run that cart, just sit back and waite till it is finished, or use cubecart.

Options: ReplyQuote
Re: can your wampserver run these script without error?
Posted by: Andy (---.it.ex.ac.uk)
Date: February 22, 2006 12:05PM

Scott you say there are lots of errors in the coding.

Could you point some or all of them out to me. Cheers!

Options: ReplyQuote


Sorry, only registered users may post in this forum.