I am trying to call data from a db and then input the data into another db
the data is for a diet website
the user chooses a recipe.
the recipe has several rows with several fields i.e.
item1, calorie, fat, protein
item2, calorie, fat, protein
item3, calorie, fat, protein
etc.
I need to pull the entries from the “recipe” db and place them into the “history” db containing the same field names.
I know I need a loop, but have not found the proper way to solve the problem
My latest attempt is included below.
I can echo the data correctly, but only the last entry enters the db
Any assist would be appreciated.
$sql=("select * from $tbl5 where recipe_name = '$recipe_name' ");
$result = mysql_query($sql);
$works = mysql_num_rows($result);
require 'my_error.php';
while($rows = mysql_fetch_array($result))
{
$item = $rows['item'];
$amount = $rows['amt'];
$calorie = $rows['calorie'];
$fat = $rows['fat'];
$fat_calories = $rows['fat_calories'];
$carb = $rows['carb'];
$protein = $rows['protein'];
$sugar = $rows['sugar'];
// insert this data into the history ref the date entered on the initial page
$sql = ("insert into $tbl3
(
user_name,
entry,
day,
item,
amt,
calorie,
fat,
fat_calories,
carb,
protein,
sugar
)
values
(
'$user_name',
'$entry',
'$day',
'$item',
'$amount',
'$calorie',
'$fat',
'$fat_calories',
'$carb',
'$protein',
'$sugar'
)
");
// end while
}
$result = mysql_query($sql);