Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMatthew Lang
13,483 Pointsmysqli_fetch_assoc only returns 1 result
Hey. I'm making a log in form and it creates a query that checks the database for any records with the inputted email by the user. That query looks like this:
"SELECT email FROM users WHERE email='$valid_email'"
I store that in a variable called $sql. I then perform the function mysqli_query, and store it in $result. Then I check for it having at least 1 row (email has been found in the database). If it has at least one row, now my thinking is to hash the password the user entered and then match it against the hashed one in the database. So, I need to retrieve the already hashed password in the database. I went ahead and done some googling and found mysqli_fetch_assoc, which returns an associative array for the result row. Sounds good, so i did: $row = mysqli_fetch_assoc($result);
By my understanding, and other examples on the web, I should now be able to do $row['password'] to access the 'password' field in that record. Though, for some reason, when debugging this $row using a foreach loop it ONLY shows the email, which is what I already have.. Also, when trying to use $row['password'] PHP gives me an error like this:
Notice: Undefined index: password
I'm asking here because I am not part of any other forum/community so hopefully I can find some help :) thank you
1 Answer
Matthew Lang
13,483 PointsFixed. I was selecting only the email , when I should've been selecting EVERYTHING using the * operator.