Soldato
Here is an example to try and explain why it works like this:
If you change your SQL query to this ("SELECT name, password, email FROM users WHERE name=? LIMIT 1", (Name,))
Then an example of a returned row would be something like this:
So, when you do result[0], it selects the first row (with all 3 fields in that row).
You could then dig deeper into it to get the single fields out:
result[0][0] = touch
result[0][1] = pass1
result[0][2] = [email protected]
It's a little more confusing in your case where the query returns a single field for each row.
Your results would look like:
So, where you had result[0], it would select the whole row with all the fields in that row (which happens to be just 1 field).
Then when you compare it to a string "password == result[0]" it is false because a string is not the same as a row (even if the row only contains a single value). You need to go into the row and select the actual field value to compare.
So result[0][0] selects the first row, then selects the first value from that row, which is a string and can be compared to the user inputted string.
If you change your SQL query to this ("SELECT name, password, email FROM users WHERE name=? LIMIT 1", (Name,))
Then an example of a returned row would be something like this:
Code:
name password email
-------------------
touch pass1 [email protected]
So, when you do result[0], it selects the first row (with all 3 fields in that row).
You could then dig deeper into it to get the single fields out:
result[0][0] = touch
result[0][1] = pass1
result[0][2] = [email protected]
It's a little more confusing in your case where the query returns a single field for each row.
Your results would look like:
Code:
password
---------
pass1
So, where you had result[0], it would select the whole row with all the fields in that row (which happens to be just 1 field).
Then when you compare it to a string "password == result[0]" it is false because a string is not the same as a row (even if the row only contains a single value). You need to go into the row and select the actual field value to compare.
So result[0][0] selects the first row, then selects the first value from that row, which is a string and can be compared to the user inputted string.