Note that there are some explanatory texts on larger screens.

plurals
  1. POForm only processes values from the last list on the page (PHP/MySQL)
    text
    copied!<p>I have a form for users to create a daily mealplan using recipes from our database. The processes are as follows:</p> <p>1) An admin selects 2 recipes for each meal (Lunch and/or Dinner), for the desired date. These selections are what will be used to populate the customer meal select lists.</p> <p>2) A customer selects 1 recipe for each meal available, for the desired date.</p> <p><strong>The PROBLEM:</strong></p> <p><strong>The form only seems to be processing the values selected from the last list displayed on the page</strong> and I am not sure why.</p> <p>Here's the code sections I've been working with. (I can post more if necessary)</p> <pre><code>// Create a new Meal Plan object $MPObj = new MealPlan($date); $MPObj-&gt;load($dbDate,$dbDate); // Just want this one day $minshow = 1; $defaultServings = 1; // Read in a list of Meals and Recipes $rc = DBUtils::fetchColumn( $db_table_meals, 'meal_name', 'meal_id', 'meal_id' ); $mealList = DBUtils::createList($rc, 'meal_id', 'meal_name'); array_unshift_assoc($mealList, 0, ""); // add an empty element to the list </code></pre> <p>--</p> <pre><code>$sql = "SELECT mplan_date, mplan_recipe, recipe_name, meal_name, recipe_serving_size FROM recipe_mealplans LEFT JOIN $db_table_meals ON meal_id = mplan_meal LEFT JOIN $db_table_recipes ON recipe_id = mplan_recipe WHERE mplan_date = '".mysql_real_escape_string($dbDate)."' AND mplan_owner = '".mysql_real_escape_string($user_SK)."' ORDER BY recipe_name"; $rc = $DB_LINK-&gt;Execute($sql); DBUtils::checkResult($rc, NULL, NULL, $sql); </code></pre> <p>--</p> <pre><code>while (!$rc-&gt;EOF) { if ($rc-&gt;fields['meal_name'] === "Lunch") { $recipeListLunch[($rc-&gt;fields['mplan_recipe'])] = $rc-&gt;fields['recipe_name'] . " (" . $rc-&gt;fields['recipe_serving_size'] . ")"; } if ($rc-&gt;fields['meal_name'] === "Dinner") { $recipeListDinner[($rc-&gt;fields['mplan_recipe'])] = $rc-&gt;fields['recipe_name'] . " (" . $rc-&gt;fields['recipe_serving_size'] . ")"; } $rc-&gt;MoveNext(); } </code></pre> <p>--</p> <pre><code>&lt;form action="index.php?m=meals&amp;amp;dosql=update&amp;amp;view=daily&amp;amp;date=&lt;?php echo $date; ?&gt;" method="post" enctype="multipart/form-data"&gt; &lt;table cellspacing="1" cellpadding="4" border="0" width="80%" class="data"&gt; &lt;tr&gt; &lt;th align="center"&gt;Remove&lt;/th&gt; &lt;th align="center"&gt;Meal&lt;/th&gt; &lt;th align="center"&gt;Servings&lt;/th&gt; &lt;th align="center"&gt;&lt;/th&gt; &lt;th align="center"&gt;Menu Options&lt;/th&gt; &lt;/tr&gt; &lt;?php // Print out all the existing meals, and some new ones for ($i = 0, $maxshow = 1; $i &lt; (isset($MPObj-&gt;mealplanItems[$dbDate]) &amp;&amp; ($i &lt; $maxshow) ? count($MPObj-&gt;mealplanItems[$dbDate]) : 0) + $minshow; $i++) { if ($i &lt; (isset($MPObj-&gt;mealplanItems[$dbDate]) ? count($MPObj-&gt;mealplanItems[$dbDate]) : 0)) { // If it is an existing meal item, then set it $meal = $MPObj-&gt;mealplanItems[$dbDate][$i]['meal']; $servings = $MPObj-&gt;mealplanItems[$dbDate][$i]['servings']; $recipe = $MPObj-&gt;mealplanItems[$dbDate][$i]['id']; } else { // It is a new one, give it blank values $meal = NULL; $servings = $defaultServings; $recipe = NULL; } /* Display Meal Lists to select from */ // Lunch echo '&lt;tr&gt;'; echo '&lt;td align="center"&gt;'; echo '&lt;input type="checkbox" name="delete_'.$i.'" value="yes"&gt;&lt;/td&gt;'; echo '&lt;td align="center"&gt;'; echo DBUtils::arrayselect($mealList, 'meal_id_'.$i, 'size=1', $meal); echo '&lt;/td&gt;&lt;td align="center"&gt;'; echo '&lt;input type="text" autocomplete="off" name="servings_'.$i.'" value="' . $servings . '" size="3"&gt;'; echo '&lt;/td&gt;&lt;td align="center"&gt;'; echo '&lt;input type="hidden" autocomplete="off" name="repeat_'.$i.'" value="1" size="3"&gt; '; echo '&lt;/td&gt;&lt;td align="center"&gt;'; echo DBUtils::arrayselect($recipeListLunch, 'recipe_id_'.$i, 'size=1', $recipe); echo '&lt;/td&gt;&lt;/tr&gt;'; // Dinner echo '&lt;tr&gt;'; echo '&lt;td align="center"&gt;'; echo '&lt;input type="checkbox" name="delete_'.$i.'" value="yes"&gt;&lt;/td&gt;'; echo '&lt;td align="center"&gt;'; echo DBUtils::arrayselect($mealList, 'meal_id_'.$i, 'size=1', $meal); echo '&lt;/td&gt;&lt;td align="center"&gt;'; echo '&lt;input type="text" autocomplete="off" name="servings_'.$i.'" value="' . $servings . '" size="3"&gt;'; echo '&lt;/td&gt;&lt;td align="center"&gt;'; echo '&lt;input type="hidden" autocomplete="off" name="repeat_'.$i.'" value="1" size="3"&gt; '; echo '&lt;/td&gt;&lt;td align="center"&gt;'; echo DBUtils::arrayselect($recipeListDinner, 'recipe_id_'.$i, 'size=1', $recipe); echo '&lt;/td&gt;&lt;/tr&gt;'; } // end for ?&gt; &lt;/table&gt; &lt;?php if isset($recipeListLunch) || isset($recipeListDinner)) { echo '&lt;input type="submit" value="Update Menu" class="button"&gt;'; } ?&gt; &lt;/form&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload