I have a mysql table which has data from all flight bookings on my booking system. When a user books a flight, the details of that booking are stored in that table along with their username.
Now, I’m making a page where all of the user’s previous flights are shown in a HTML table, and everything works except the code which filters results to those only from that user.
This is the (part of) code I’m using;
$query_string = "SELECT name, seats, departure, destination, class, username, miles, timestamp FROM $tablename WHERE username IN ('$username')";
The username field is where the user who booked the flight’s username is stored, and the $username variable contains the current logged in user’s username. What I’m trying to do is only show the fields where $username matches username (hence only showing bookings for the current user).
When I use the above code without WHERE username IN ('$username'), it displays all the data, but when I add the above code, it displays nothing when there are matches.
If anyone could help fix my code I would greatly appreciate it.
Thanks!
You’re using
INincorrectly.INcompares comma-separated lists of strings or values. This can be literal:OR it can come from a subquery:
If you want an exact match, your
WHEREclause should beIf that still doesn’t work, you MUST verify that you’re sending your database the correct query.