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 7576181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:51:35+00:00 2026-05-30T16:51:35+00:00

I have two files in use. The first is a front end select box

  • 0

I have two files in use. The first is a front end select box with a list of dynamically populated char/text values that uses POST to send the selected value to a back end file. This back end file assigns this value to a variable and that variable is then used in the following query:

    $query = "SELECT DoctorName, Speciality FROM hospital WHERE HospitalName =".$hosname;

However, I keep getting the Invalid Query message I have set in my or die(); and I have no idea why. The full section of php code on the backend file is as follows:

    $conn = mysqli_connect("localhost", "root", "") or die ("No connection");
    mysqli_select_db($conn, "hospitaldb") or die("db will not open");

    $hosname=$_POST['valuelist'];
    $query = "SELECT DoctorName, Speciality FROM hospital WHERE HospitalName =".$hosname;

    $result = mysqli_query($conn, $query) or die("Invalid query");

    echo "<table border='1'><tr><th>mDoctorName</th><th>Speciality</th></tr>";

    while($row = mysqli_fetch_array($result))
      {
      echo "<tr><td>" . $row[0] . "</td><td>" . $row[1] . "</td></tr>";
      }
    echo "</table>";
    mysqli_close($conn);

Note: I have checked that the value from the select box is being passed in using print and it is. Any help would be greatly appreciated.

*I am only testing this locally but thanks to all who recommended mysql_real_escape_string() to protect against injections.*

  • 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-05-30T16:51:37+00:00Added an answer on May 30, 2026 at 4:51 pm

    The resulting SQL query you want would be something like;

    SELECT DoctorName, Speciality FROM hospital WHERE HospitalName = 'MyHospital'
    

    In other words, you need to add quotes to your query creation;

    $query = "SELECT DoctorName, Speciality FROM hospital WHERE HospitalName = '".$hosname."'";
    

    You should really also escape the hospital name using mysql_real_escape_string() before just inserting it into a query.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two files (f1 and f2) containing some text (or binary data). How
I have two files which both contain a list of words. Is there an
I have two files and the content is as follows: alt text http://img144.imageshack.us/img144/4423/screencapture2b.png alt
Alright, I have two files. They are the EXACT SAME. The first file is:
I'm trying to convert Morse code into text. I have two text files to
I have two files. First one has 482 lines. Second one has only 519
I have two *.sql files that I use when creating a new web site
I have two files, one has a list of codes and the other has
I have two files with slight differences. A normal diff will show me the
I have two files, A is a subset of B. Both A and B

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.