Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8312479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:10:44+00:00 2026-06-08T20:10:44+00:00

I have a mysql table which has data from all flight bookings on my

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T20:10:48+00:00Added an answer on June 8, 2026 at 8:10 pm

    You’re using IN incorrectly. IN compares comma-separated lists of strings or values. This can be literal:

    WHERE username IN ('user1', 'user2', 'user3')
    

    OR it can come from a subquery:

    WHERE username IN (SELECT username FROM users)
    

    If you want an exact match, your WHERE clause should be

    WHERE username = '$username'
    

    If that still doesn’t work, you MUST verify that you’re sending your database the correct query.

    echo $query_string;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table which is being dynamically populated from MySQL. The table has
I have an application which collects data into a mysql table. The table has
I have a MySQL table which has a product_id field (big integer) 1102330008 1102330025
I have a huge MySQL table which has its rows encoded in UTF-8 twice.
if i have a table which has columns with fixed lenght, Will mySQL count
I have a table in MySQL 4.0 which currently has a year field as
I have a MYSQL-Table which stores scores. Every time a user improves a new
i have a php code which selects and shows data from my 'elections' table.
I have a table like this in mysql called links_tbl which has 5 rows
I have a MySQL table which I want to populate with some dummy data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.