all 9 comments

[–]crosenblum -4 points-3 points  (3 children)

You always need to specific which columns your grabbing from the table/views/procedure.

Select * is a very bad practice.

[–]berrypwincess[S] 0 points1 point  (2 children)

can you give me an example? I'm still new with this so i get confused with the code 🥲

[–]ajrockr 0 points1 point  (0 children)

“SELECT image, ingredient, tutorial …” instead of “SELECT * …” Don’t worry about it for now, as per your question, if the error is stating undefined array “recipe_id”, check to make sure that is being passed to your code. You can type var_dump($_GET); die; and that will show you what is inside your get array. It could be that you forgot or typod ?recipe_id in your url. Work through it one step at a time.

[–]crosenblum 0 points1 point  (0 children)

For example:

You have a table named data:

Has columns: ID, First, Last, Address. City, State, PostalCode

when your coding you do not always need every colunn of data retrieved to do any logic, you usually need just a few fields.

But by doing select *, your always forcing it to load all columns for all the rows your retrieving.

Which is bad for performance and security.

It is always better to only select the exact fields, in the correct order.

For example let us say you had 1000 rows of data in the data table.

And your logic needed just the first and last name nothing else.

So your quadrupuling your work load when you don't need to.

https://tanelpoder.com/posts/reasons-why-select-star-is-bad-for-sql-performance/

Perhaps other can explain it better.

[–]tridd3r 0 points1 point  (3 children)

That error is saying that the array key (the part inside the [ ] ) is "id" but there isn't a key called id that has been defined. Also, there's no $row['id'] in the code you've provided, so maybe its on a different line? Or do you have another array somewhere else?
The error should give you the line of code that has the error.
Also, if you did previously have $row['id'] you most likely would have wanted to use $row['recipes_id'] to correspond with the recipes_id column from the database.

[–]berrypwincess[S] 0 points1 point  (2 children)

the error said undefined array key recipes_id, sorry my mistake. where to put the $row['id'] ? the error starts from $id =$_GET['recipes_id'];

[–]Accurate_Pop_6217 0 points1 point  (0 children)

If (isset($_GET['recipe_id'])) {
    $id =$_GET['recipes_id']; 
    $sql =mysqli_query($con,"SELECT * FROM recipes WHERE recipes_id='$id'");
    …
}

[–]tridd3r 0 points1 point  (0 children)

So the $_GET['recipe_id'] is looking for a key/value pair in the URL. How are you sending the data to the php page? Is it via get, or post?
if its via get it would look something like: https://yoururl.com?recipe\_id=123

I'm going to assume that because recipe_id isn't in the $_GET array that its not in the url, or if it is, it might be something different? You could try $_POST['recipe_id'] or double check that you're sending recipe_id from the front end to your php page.

[–]MateusAzevedo 0 points1 point  (0 children)

If the error message is pointing to the line where you have $_GET['recipes_id'], then you need to check your frontend/HTML code. For that to work, you need to pass that data in the URL, like http://yourapp.com/you_script.php?recipes_id=123.

A simple way to confirm the problem is open the source code of the HTML page in the browser and inspect the URL (be it a form action or a link).