For one of my wife’s xmas gifts, I’m turning our massive, beat up cookbook binder into an online cookbook so she can add/edit/search/delete recipes and use our iPad to do all this.
I’ve run into a problem that I’m sure is very basic for some people on here, but I can’t seem to get it to work.
Basically I have a “view.php” page that displays all the recipes I’ve entered into mySQL database.
What I’ve done is create a dynamic “recipe.php” page that will display all the recipe info for whichever recipe she clicked on, instead of creating a static page for EACH recipe (which would take forever to do).
Essentially this is what I’m trying to do:
- Pass the “ID” variable of the recipe from “view.php” to “recipe.php”
- Populate all the fields (ingredients, cooking steps, etc) from the database, BASED on the ID from the “view.php” page.
An example URL that is passed from “view.php” is mywebsite.com/cookbook/recipe.php?id=3
View.php code:
Here is the loop I have to display all the recipes
[php] <?php
while($row = mysql_fetch_array($sql_result)) {
$id = $row[“id”];
$title = $row[“title”];
$category = $row[“category”];
$subcategory = $row[“subcategory”];
$subcategory2 = $row[“subcategory2”];
$preptime = $row[“preptime”];
$cooktime = $row[“cooktime”];
$serves = $row[“serves”];
echo “
echo "
echo “
echo “
echo “
echo “
echo “
echo “
echo “
echo "
echo “
}
mysql_free_result($sql_result);
?>[/php]
The code for the “recipe.php” page is:
[php]<?php
$frmID = $_GET[“id”];
$con = mysql_connect(“localhost”, “username”, “password”) or die(“Could not connect to server”);
$db = mysql_select_db(“DB”, $con) or die(“Couldn’t select database”);
$result = mysql_query(“SELECT * FROM tblCookbook where id=’$frmID’”);
while($row = mysql_fetch_array($result))
{
?>[/php]
Displaying the info for the recipe:
[code]
Now, the thing that is puzzling me is that the “Title” for the dish will work, but that’s it. Nothing else populates.
(for example, “Category” from the above code snippet doesnt work, but the “Title” does.
Any help would be MUCH appreciated!