I have a inefficiently constructed form that is obviously sending one type of data per SELECT element. For simplicity's sake, here's an example.
The form posts data from 2 SELECT elements, but it actually needs to contain 3 pieces of data. To the user, the SELECTs do contain 3 pieces of data; one SELECT denotes quantity and the other SELECT denotes an item name AND a price using text between the OPTION tags.
So, the form is sending only $quantity and $itemname
In processing, I am trying to construct a bunch of IFs or a SWITCH to provide for the missing prices. Being that the string associated with $itemname is unique, I am trying to make a "key" that provides the price. My logic is, if $itemname contains "One Inch Nut" I could find for $price with something like:
if ($itemname = "Once Inch Nut;") { $price = .25; }
And if $itemname were something else, I would add another IF or IF else or CASE in a switch.
In fact, I am doing just that, yet when I select another OPTION from the SELECT, the $price and even the $item name are defined as the last "IF" in my stack of "IFs"
So if I were to select like, the 3rd item in a 20 item SELECT grouping, when it came time for me to use the variable (adding, echoing, whatever) I'd end up with the end of the "IF stack"
Obviously, my logic and understanding of IE ELSEIF ELSE is flawed.
Ideas on how to make this "Key" from a variable's string data?
Thanks, Rob
See below for an abridged example of what I thought would work:
Suppose the form posts "cat" for $itemname and "3" for $qty
<?
$itemname = $_POST['specificitem'] ;
$qty = $_POST['quantity'] ;
if ($itemname = "cat;") { $price = 2.25; }
if ($itemname = "dog;") { $price = 1.25; }
if ($itemname = "hamster;") { $price = 3.25; }
if ($itemname = "parakeet;") { $price = 7.25; }
if ($itemname = "werewolf;") { $price = 122.25; }
echo $itemname;
echo "$"$price;
?>
Should yield: cat $2.25 ????