r/CodingHelp • u/Pigeonsss • Dec 11 '21
[SQL] SQL statement is refusing to pull data from this table. Session variable has data, have tested with other variables as well.
26
Upvotes
2
u/bitdonor Dec 11 '21
You are missing a step.
mysqli_query returns the result object, which is not your data yet.
You would need to fetch the data from that result object using mysqli_fetch_assoc.
Check it our here and the examples provided
1
1
Dec 11 '21
Print the query, copy it and then run it directly in the database
2
u/Pigeonsss Dec 11 '21
The query works perfectly fine within the database and returns accountID like it should. I just can't seem to have it echo the $id_result as a session variable or as a regular one.
3
11
u/Urd Professional Coder (C#) Dec 11 '21 edited Dec 11 '21
I'm not sure single quotes are the correct delimiter for MySQL entity names, some googling around shows me that it's the backtick character: `
SELECT
accountIDFROMuserinfoWHEREusername= 'blah'You need to be really really really careful about constructing SQL queries using concatenation, that is the easiest way to end up with a SQL injection vulnerability. Parameterized queries are the best way to handle passing values into things like where clauses. https://www.php.net/manual/en/pdo.prepared-statements.php