for some reason this hasn’t been inserting into the database. I’m puzzled. It runs fine. I have no idea what’s wrong.
It should be updating a table called user_foods in a database called vitamink, but it isn’t. It’s connected properly. That’s not the problem.
<?php include 'top.php'; ?>
</head>
<div id="container">
<?php include 'header.php'; ?>
<?php include 'nav.php'; ?>
<div id="content-container">
<div id="content_for_site">
<h2>Find A Food</h2> <br />
<?php
$query = "SELECT
`id`, `user_submitted_id`, `approved`, `name`, `source`, `vit_k`, `cal`,`protein`, `fiber`, `carbs`, `sugar`, `sodium`, `chol`
FROM `foods`
";
$query_run = mysql_query($query);
?>
<br /><br />
Food |
Vitamin K (mcg) |
Fiber (g) |
Calories |
Protein (g) |
Carbs |
Sugar (g) |
Sodium (mg) |
Cholesterol |
Source
<br />
<form action="find-a-meal.php" method="POST">
<?php
while ($row = mysql_fetch_assoc($query_run)){
?>
<input type="checkbox" name="<?php
echo $row["id"];
?>"<?php
echo ' value="'.$row["id"].'" />'
.$row["name"]." | ".
$row["vit_k"]." | ".
$row["fiber"]." | ".
$row["cal"]." | ".
$row["protein"]." | ".
$row["carbs"]." | ".
$row["sugar"]." | ".
$row["sodium"]." | ".
$row["chol"]." | ".
$row["source"].
'<br />';
}
?>
<br /><br />
<input type="submit" value="Add Food to my Meal Planner Queue">
</form>
<?php
// send the foods to the mysql database
if (isset($_POST[$row["id"]]) && !empty($_POST[$row["id"]])){
$id = $_POST[$row["id"]];
$query = "INSERT INTO `users_foods` VALUES('','".$_SESSION['user_id']."','".$id."','','','','')";
$query_run = mysql_query($query);
}
?>
</div>
row[“id”] isn’t in the post array. the post array only contains numbers (the ids).