I am implementing a small online purchase page with a very few products.
<?php
$item_name = "lamp";
$item_price = 29.99;
$item_category = "furniture";
$item_Dollar = 29;
$item_Cents = 99;
?>
How do I go about it? It's only 2 product types and basically only prices would differ so there is no need for a database. I was thinking of including a .php file containing all the prices and having a function there that will switch($id)
between them and reassign the values.
<?php
function selectProduct($id) {
switch($id) {
case 1:
$item_name = "lamp";
$item_price = 19.99;
$item_category = "furniture";
$item_Dollar = 19;
$item_Cents = 99;
break;
case 2:
// and so on...
default: break;
}
}
?>
The logic enters the respective cases but it does not reassign the instance variables. For some reason when I try to access them on another page after require_once(pricings.php);
they are empty. I am not very familiar with PHP which probably made itself obvious from the code. What am I doing wrong?