Click here to Skip to main content
15,919,931 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So I have a sql query (below) which is supposed to use the login id from login page and do a query based on that user. I can't figure out the correct formatting for the $_session, seems to print the correct user id in the error message but the rest of the query is not pulling any data.

error showing: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '27008 order by Policy asc' at line 1

What I have tried:

$sql = "select pendingindex.* from pendingindex join sorttest on pendingindex.pendreckey = sorttest.pendreckey where agentid in( select agentid from pinagentid where pin = . {$_SESSION['user_id']} order by $sort $sort_order";
Posted
Updated 7-May-19 8:39am

select pendingindex.* from pendingindex
join sorttest on pendingindex.pendreckey = sorttest.pendreckey
where agentid in ( select agentid from pinagentid where pin = . {$_SESSION['user_id']} order by $sort $sort_order

Notice your "agentid in (" subquery . . . you did not have a closing ")" before your ORDER BY clause.

Try that for a start.
 
Share this answer
 
First problem I see is that you have the potential for a SQL Injection vulnerability by way you concatenate together your SQL command. How you should be doing this is by creating a prepared statement and then binding in a parameter.

Second item I see is an error there is no closing parenthesis in your subquery.

Third item I see is in your ORDER BY clause; the two items should be separated by the items are not separated by a comma

References:
PHP: mysqli::prepare - Manual[^]
PHP: PDOStatement::bindParam - Manual[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900