The nub of my point was this:
That you can write in HTML all the prices and descriptions you want, but some unscrupulous person can change the total to 1 penny, and submit that to your email script, and to your paypal account, so you have to work out the full price on the backend (in PHP).
If you are just dabbling with PHP and don’t want/need a database you could just have a multi-array and maintain it by hand, put that in a file called books_array.php
You’d then include() the file with that array in two scripts.
Lets name them:
books.php (the HTML form)
order.php (the form “handler” or processor)
books_array.php
<?php
// set up your array here
$books = array(
0 => array(
'id' => 1,
'title' => 'Textbook One',
'price' => 12.99,
),
1 => array(
'id'=>2,
'title' => 'Textbook Two',
'price' => 10.99,
),
// and so on
);
books,php
<?php
include 'books_array.php';
?>
// enter your page html here ...
// start your form ....
<?php
foreach($books as $bk){
// this is on two lines so you can read it without scrolling on SP
echo '<p><input type=checkbox name=book_id['. $bk['id'] . '] id=book_id['. $bk['id']
. '] >' . $bk['price'] . ' : ' . $bk['title'] . '</p>';
}
?>
// end your form
// the rest of your html
order.php
<?php
if(isset($_POST)){
var_dump($_POST);
}
include 'books_array.php';
// check which books were picked
// grab the price
// add the prices up
// send the email
// sent to paypal
// send notification to the user onscreen **
** you might want to do this first, kind of “are you sure you want to order all these books for $xx.xx?”
I have just pseudocoded roughly what order.php should do, but you should get the gist, that you maintain a single array of books, but that it serves 2 purposes - to generate the html list, and to provide something to generate the prices from.
We can fill out those lines of pseudocode when you have got had a play with that and got some more realistic data loaded, filled out your html page and so on.