farahZ Posted May 29, 2013 Share Posted May 29, 2013 i can't figure out where my problem is!!I'm trying to input the quantity (text box) of each food chosen (drop down list) by the user.. food inputs working fine but quantity is storing the first item in the array only! if (!isset($_SESSION['foodTypes'])) { // if the session is not yet created, create it now $_SESSION['foodTypes'] = array(); $_SESSION['Quantity']= array (); $c=0; } // check to see if the newly added food type is not already in the array if (in_array($_POST['foodType'], $_SESSION['foodTypes']) === false) { // The selected food item is not in the array // add the selected food item to total food array $_SESSION['foodTypes'][] = $_POST['foodType']; $foodQuan = $_POST['fooDquantity']; $foodVal=$_POST['quantityValue']; //only first item of quantity is added $_SESSION['Quantity'][$c]= $foodQuan ." ". $foodVal; echo $_SESSION['Quantity'][$c]; echo $c++; } //submitting the food to the database (first item of quantity is sent only) // user presses submit, after he is done adding all food he wants $c=0; (starting from ) to pass by all quantity registered) foreach ($_SESSION['foodTypes'] as $food) { $cal=0; $sql=""; $clid=$_SESSION['views'][0]; $q=$_SESSION['Quantity'][$c]; echo $q; $sql = "INSERT INTO fooddiary (ID, Date, DayTime, Food, Quantity, Calories) VALUES ('$clid', '$date', 'Lunch', '$food', '$q', $cal)"; $c++; $result = mysqli_query($con, $sql) or die(mysqli_error()); } Quote Link to comment Share on other sites More sharing options...
ginerjm Posted May 29, 2013 Share Posted May 29, 2013 try adding some echos and see what is being captured. debugging is an essential part of programming. Quote Link to comment Share on other sites More sharing options...
farahZ Posted May 29, 2013 Author Share Posted May 29, 2013 Hey ginerjm, I tried that.. The problem is in the first section.. quantity isnt being registered and I dont know the reason for this Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.