Search the Community
Showing results for tags 'php button click session'.
-
hello, what am trying to do is that to allow the user choose from a dropdown list items (item by item) and add each, constantly viewing the added items. the added items must be saved in an array (foodSelected). the problem i am facing is with creating is with creating a variable, and incrementing this variable by one each item the user adds an item!! i want that counter for several reason: - array printing - sending the array items to the database i read in the forums something about $_session variables, i tried to implement it.. but still got errors thats the code i wrote, its a calorie counter.. i will appreciate any help <?php session_start(); ?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Calorie Counter</title> </head> <body> <p>It's Breakfast </p> <p> <form action="" method="post"> <p> <select name="foodType" id="foodType"> <option selected="selected">Labneh</option> <option>Cucumber</option> <option>Tomato</option> <option>Lettuce</option> <option>Cucumber Pickles</option> <option>Olive Oil</option> <option>Cucumber without peal</option> <option>Olive Black</option> <option>Olive Green</option> </select> <input name="submit" type="submit" id="submit" value="add"> </p> </p> </form> <?php if (isset($_POST['submit'])) { chosenItems(); } $_SESSION['counter'] = (!$_SESSION['counter']) ? 0 : $_SESSION['counter']; if($_POST['add']) { $_SESSION['submit']++; } function chosenItems() { $foodSelected[$counter]= $_REQUEST["foodType"]; echo "food added: ", "<BR>"; print_r($foodSelected); } ?> </body> </html>