Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Shivamyadav's avatar

database sql query error?

code

$loggedIN = $_SESSION['id'];
$sql = "SELECT * users from users Inner Join  students on  students.user_id = users.id WHERE users.id = $loggedIN";
$data = mysqli_query($conn, $sql);

and error https://paste.pics/d0bdd014f4f9bb6678d41c803929790f and i want to fetch alll the created data by the logged in users?

0 likes
10 replies
Sinnbeck's avatar

You have users twice. Did you mean

SELECT users.* from users Inner Join  students on  students.user_id = users.id WHERE users.id = $loggedIN
Shivamyadav's avatar

@Sinnbeck no sir. in the image it shows after i removed it from the query .. You can see it on the $sql variable

azimidev's avatar
azimidev
Best Answer
Level 55

It'd be nice to paste the error here instead of screenshots. syntax error in the SQL query: there is no "from" keyword after the asterisk (*).

The correct query should be:

$loggedIN = $_SESSION['id'];
$sql = "SELECT * FROM users INNER JOIN students ON students.user_id = users.id WHERE users.id = $loggedIN";
$data = mysqli_query($conn, $sql);

SELECT * FROM users

NOT

SELECT * users from

1 like
Shivamyadav's avatar

@azimidev can I know sir what is the difference between these two queries.. 1 st one is showing error that unknown column 'users.id' in where clause and 2nd query is working properly.. why


SELECT * FROM users INNER JOIN students ON students.user_id = users.id WHERE users.id = 15;
SELECT * FROM users INNER JOIN students ON students.user_id = users.id WHERE users.id = 15;
Sinnbeck's avatar

@Shivamyadav they are 100% identical. Not a space or anything. So we are missing some information here. The code for how you are doing each?

Please or to participate in this conversation.