I need to restrict access to other table id's by making a check against an (id) of a table named users and then check that the (user_id) of another table is the same i.e

table1

id username password

table2

id somedata user_id


if table1 id is the same as table2 user_id then show table2 contents but only show the contents of table2 where the user_id exists and still use the id row of table2 to display contents in a url like ?id=12 only if its the users data if not frow an error

How would I go about this I have tried and tried but no joy

I have some code setup that I been trying I can post if like.

Member Avatar for diafol

You need to use an INNER JOIN.

Something like...

SELECT t1.id, t2.somedata FROM table1 AS t1 ON table2 AS t2 INNER JOIN t1.id = t2.user_id WHERE t1.id = $id

I get it now.. how confusing, I was stuck thinking I needed to php to check it lol.
How simple I never thought you could use an id as another id with a query nice one for your help on this.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.