View Full Version : Anyone know a good tutorial for a shopping cart without a database?
I've just started learning php and I need a shopping cart which doesn't rely on a database. I can't find any tutorials where this is the case. I'm going to learn it with a database soon, but the site I am doing at the moment doesn't need it.
Basically there are a few things which will be made once sold, so don't require a db. All i need really is a php page which stores whatever is sent to it via a link. So it doesn't even have to be a shopping cart!
Can anyone point me in the right direction?
Thanks!
lli2k5
11-25-2006, 04:50 AM
you should learn how to use a database. It's actually easy to do stuff with that then without a database. That's why they are there :)
The closest thing I can think of is store things in the link.
i.e. index.php?a=x
would store the value x in a. So, use $_GET['a'] to get the value of x, whether you need it. To add more values, just rewrite the link.
firepages
11-25-2006, 05:46 PM
store the purchases in a session ..e.g.
<?php
$_SESSION['CART'][0]['product_code']='123123';
$_SESSION['CART'][0]['price']='99.00';
$_SESSION['CART'][0]['description']='blah';
$_SESSION['CART'][1]['product_code']='22323';
//........etc
?>
that way you dont have to keep passing the variables around.. remember to use session_start(); on any pages that need access to the data.
you can even store the session data for later use ...
<?php
/*save it*/
$save = serialize($_SESSION['CART']);
$fp=fopen('some_filename.saved.php','w');
fputs($fp,$save);
fclose($fp);
/*reopen it*/
$_SESSION['CART']=unserialize(file_get_contents('some_filename.saved.php'));
print_r($_SESSION);
?>
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.