0

I've spent the last few days understanding and getting the correct code combinations to create a form to enter recipes into a database. I know there are "similar" questions and discussions about Concat syntax, but recipes is something I've never found to go from start to finish, including the html.

Here is where I found the data for creating the database and then (attempting) to use the below code (from guignol - that was the most complete and most recent code I could find): SO recipe database

I've added several columns to the "recipe" table. I don't have a problem (now) entering data into the database using all the found code (although I did have to update and make minor changes to eliminate errors using the code "as-is").

I am using mysqli and php in case it makes any difference. If anybody has a better solution I'm happy to switch horses. I also know many people have various methods. But recipes is a hard nut to crack because of the relationships and variations for each entry. I'm hoping the great "recipe guru" will find this post and advise me well.

The "full" error here:

Parse error: syntax error, unexpected 'recipes' (T_STRING) in C:\wamp64\www\LocalHire\trials\mencook-recipes.php on line 57

Line 57 is the first LEFT JOIN syntax.

I'm still researching and have found the solution to the "first" error. So instead of getting booted "again" because the question is similar to other answers that are "NOT" answers to my question, if this one gets booted I'll just continue to research. Many answers are incomplete, especially for those not educated in CONCAT and LEfT JOIN. So when finding "an" answer, I usually try the code, get a lot of errors and try to resolve them 1-by-1. But in this case, I have no clue how to LEFT JOIN. I did finally get passed the CONCAT.

Here's what I have for selecting the data:

$sql = "SELECT recipes.id, recipes.name AS recipeName, ingredients.name AS ingredientNeeded, CONCAT(ingredients_recipes.Qty,' ',neededUnities.name) AS neededQuantity, CONCAT(inventories.qty,' ',inventoryUnities.name) AS availableQuantity FROM recipes"

LEFT JOIN ingredients_recipes ON recipes.id=ingredients_recipes.recipe_id 
LEFT JOIN ingredients ON ingredients_recipes.ingredient_id = ingredients.id 
LEFT JOIN inventories ON ingredients.id=inventories.ingredient_id 
LEFT JOIN unities AS inventoryUnities ON inventories.unity_id=inventoryUnities.id
LEFT JOIN unities AS neededUnities ON ingredients_recipes.unity_id=neededUnities.id

WHERE inventories.`update` = (SELECT MAX(`update`) FROM inventories AS inv WHERE inv.ingredient_id = inventories.ingredient_id);
Mr. Garrison
  • 59
  • 1
  • 7
  • What happened to your last question? This looks almost the same. – Dharman Jan 08 '20 at 17:01
  • Duplicate of [How can I get my recipe data using the correct syntax for concat?](https://stackoverflow.com/questions/59637342/how-can-i-get-my-recipe-data-using-the-correct-syntax-for-concat) – Dharman Jan 08 '20 at 17:03
  • You need to show us the PHP code if you are getting an error in php. Please don't ask another question, edit the original – Dharman Jan 08 '20 at 17:04
  • 1
    You can't use single quotes twice, unescaped. You must be encapsulating the PHP string in single quotes as well. Your `,' ',` breaks that encapsulation and the PHP processor can't handle that. – user3783243 Jan 08 '20 at 17:04
  • The error message doesn't match the code you provided. Please update with the PHP code. Note if this somehow is your real code and the parser is reporting incorrectly your `LEFT JOIN` and other SQL needs to be in a string. – user3783243 Jan 08 '20 at 17:17
  • Dharman - when I initially posted, you flagged the question, and there was a notice stating that if my question was not answered I should ask another question. None of my questions have been answered. I'm sorry if the questions I asked are "similar" to others, but they are not the same. I'm asking for clarification because NONE of the answers, including those to which you referred, provide complete information - only partial. How about, "Why is LEFT JOIN causing an error? Is it syntax? Is it improper coding? – Mr. Garrison Jan 08 '20 at 21:08
  • I've just found that from just before SELECT through to just before the last semi-colon should be in quotes. I got past the above error, and now I can work on the method to display the results. I don't think my question was that out of line. I only needed the "kick" to enclose the entire string in double quotes. Thanks. – Mr. Garrison Jan 08 '20 at 21:14

0 Answers0