WD1812 Posted March 28, 2010 Share Posted March 28, 2010 Hi, I'm a newbie still learning php/mysql, and hoping someone can help straighten this out. First Table - Recipes: Columns are: recipe_id (Set as Primary Key, Auto Increment) title ingredients prep serves Second Table - Categories: Columns/values are: category_id (Values: 1, 2, 3, 4, 5, 6, 7) category_name (Values: Desserts, Drinks, Fowl, Meat, Pasta, Seafood, Vegetables) Here's the scenario: Jennifer enters the following Recipe into a form on the Desserts Page: Title: Apple Strudel Ingredients: Apples, Flour, Water Prep: Core and slice apples, etc. Serves: 6 Category: 1 Mary enters the following Recipe into the same form: Title: Blueberry Pie Ingredients: Blueberries, Flour, Water Prep: Wash blueberries, etc. Serves: 6 Category: 1 The title of each recipe now appears above the form on the Desserts Page, which is what I want. Linda decides she wants to view each of the recipes, and goes to the Desserts Page. She clicks on Apple Strudel, and the page that's created shows that recipe. However, when she clicks on "Blueberry Pie," while the ending of the URL address is recipesdesserts.php?recipeID=1Blueberry (recipesdesserts.php is the display page), the actual page that's created shows the recipe for the Strudel. As I understand it, I need to print the ID in the link and not the title. Could someone please take a look at this code, and see what corrections need to be made? <li><a href="../Recipes/recipesdesserts.php?recipeID=1<?php echo $row_GetRecipes['Title']; ?>"><strong><?php echo $row_GetRecipes['Title']; ?><?php print_r($recipes); ?>/strong></a></li<?php } while ($row_GetRecipes = mysql_fetch_assoc($GetRecipes)); ?> Thank you! Link to comment https://forums.phpfreaks.com/topic/196801-newbie-needs-help-with-correcting-code/ Share on other sites More sharing options...
Orionsbelter Posted March 28, 2010 Share Posted March 28, 2010 could you post the code for recipesdesserts.php Link to comment https://forums.phpfreaks.com/topic/196801-newbie-needs-help-with-correcting-code/#findComment-1033106 Share on other sites More sharing options...
Orionsbelter Posted March 28, 2010 Share Posted March 28, 2010 we need to see the whole code and the $GetRecipes query Link to comment https://forums.phpfreaks.com/topic/196801-newbie-needs-help-with-correcting-code/#findComment-1033110 Share on other sites More sharing options...
WD1812 Posted March 28, 2010 Author Share Posted March 28, 2010 <?php require_once('../../Connections/wilsonclann_db.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $currentPage = $_SERVER["PHP_SELF"]; $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO Recipes (Title, Ingredients, Prep, Serves) VALUES (%s, %s, %s, %s)", GetSQLValueString($_POST['Title'], "text"), GetSQLValueString($_POST['Ingredients'], "text"), GetSQLValueString($_POST['Prep'], "text"), GetSQLValueString($_POST['Serves'], "text")); mysql_select_db($database_wilsonclann_db, $wilsonclann_db); $Result1 = mysql_query($insertSQL, $wilsonclann_db) or die(mysql_error()); $insertGoTo = "recipesdesserts.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } $maxRows_GetRecipes = 10; $pageNum_GetRecipes = 0; if (isset($_GET['pageNum_GetRecipes'])) { $pageNum_GetRecipes = $_GET['pageNum_GetRecipes']; } $startRow_GetRecipes = $pageNum_GetRecipes * $maxRows_GetRecipes; mysql_select_db($database_wilsonclann_db, $wilsonclann_db); $query_GetRecipes = "SELECT Recipes.Title, Recipes.Ingredients, Recipes.Prep, Recipes.Serves FROM Recipes"; $query_limit_GetRecipes = sprintf("%s LIMIT %d, %d", $query_GetRecipes, $startRow_GetRecipes, $maxRows_GetRecipes); $GetRecipes = mysql_query($query_limit_GetRecipes, $wilsonclann_db) or die(mysql_error()); $row_GetRecipes = mysql_fetch_assoc($GetRecipes); if (isset($_GET['totalRows_GetRecipes'])) { $totalRows_GetRecipes = $_GET['totalRows_GetRecipes']; } else { $all_GetRecipes = mysql_query($query_GetRecipes); $totalRows_GetRecipes = mysql_num_rows($all_GetRecipes); } $totalPages_GetRecipes = ceil($totalRows_GetRecipes/$maxRows_GetRecipes)-1; $queryString_GetRecipes = ""; if (!empty($_SERVER['QUERY_STRING'])) { $params = explode("&", $_SERVER['QUERY_STRING']); $newParams = array(); foreach ($params as $param) { if (stristr($param, "pageNum_GetRecipes") == false && stristr($param, "totalRows_GetRecipes") == false) { array_push($newParams, $param); } } if (count($newParams) != 0) { $queryString_GetRecipes = "&" . htmlentities(implode("&", $newParams)); } } $queryString_GetRecipes = sprintf("&totalRows_GetRecipes=%d%s", $totalRows_GetRecipes, $queryString_GetRecipes); ?> This is the code for where the recipe is displayed within the body of the page: <div id="titlecontainer"> <?php echo $row_GetRecipes['Title']; ?></div> <div id="ingredientscontainer"> <?php echo $row_GetRecipes['Ingredients']; ?></div> <div id="prepcontainer"> <?php echo $row_GetRecipes['Prep']; ?></div> <div id="servescontainer"> <?php echo $row_GetRecipes['Serves']; ?></div> Thank you. Link to comment https://forums.phpfreaks.com/topic/196801-newbie-needs-help-with-correcting-code/#findComment-1033119 Share on other sites More sharing options...
Orionsbelter Posted March 28, 2010 Share Posted March 28, 2010 you use recipeID as parameter in the url but in the script i don't see you use the recipeID at. I thought you would be declaring this so you can use it in your query for example i though you would be using recipeID=THE ID OF THE RECIPE YOU WANT TO VIEW for example recipeID=1. Then i though you would then be using that in a query to pull that recipe's info for example SELECT * FROM recipes WHERE id='".$_GET['recipeID']."'] Link to comment https://forums.phpfreaks.com/topic/196801-newbie-needs-help-with-correcting-code/#findComment-1033130 Share on other sites More sharing options...
WD1812 Posted March 28, 2010 Author Share Posted March 28, 2010 All of the code was generated by DW CS4. Maybe I'm not explaining things correctly, or I'm just lost. Because I can't enter a specific ID if I don't know what a user is going to Title the recipe that they enter? So now my question is, how do I get everything in sync? Link to comment https://forums.phpfreaks.com/topic/196801-newbie-needs-help-with-correcting-code/#findComment-1033136 Share on other sites More sharing options...
Orionsbelter Posted March 28, 2010 Share Posted March 28, 2010 So you haven't hand coded anything? Link to comment https://forums.phpfreaks.com/topic/196801-newbie-needs-help-with-correcting-code/#findComment-1033175 Share on other sites More sharing options...
WD1812 Posted March 28, 2010 Author Share Posted March 28, 2010 Correct. It's all been done via DW. Link to comment https://forums.phpfreaks.com/topic/196801-newbie-needs-help-with-correcting-code/#findComment-1033199 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.