Jump to content

filling 2 array sessions


farahZ

Recommended Posts

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());
}
 

 

Link to comment
https://forums.phpfreaks.com/topic/278549-filling-2-array-sessions/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.