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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:55:36+00:00 2026-06-11T18:55:36+00:00

I have been trying to run a mySQL query that populates a HTML form

  • 0

I have been trying to run a mySQL query that populates a HTML form where I present a tag. I would like to populate both the value and the text from the mySQL table.
Here is what I tried based on finding things on different web sites, and it did not work

<select name="id">
   <?php

    require_once dirname(__FILE__) . '/db_connect.php';
    $db = new DB_CONNECT();

    $query="SELECT id, name FROM file order by name";
    $result=mysql_query($query) or die ("Query to get data from firsttable failed: " .mysql_error());

    while ($row = mysql_fetch_array($result)) {
    $id = $row[id];
    $name =$row[name];
      echo "<option value=\"$id\">
            $name
            </option>";
     }
   ?>
    </select>

Comment:
Did not work refers to the fact that the select drop down is empty.
I did pull the PHP out of the form and put it in it’s own name.php file to try and run it. it seemed to work. So I added echo statements in the php to echo out the start and end of the form, and the initial select line. This worked just great, no problems, the drop down was populated just fine.
Back on the HTML form above, I did add a few other echo statements in the PHP to output some debug statements. The firs echo is always ignored, it does not add any select item. the other echo lines only adds the text specified, variables are output as the variable name, not the content. so $name shows up in the select drop down.

  • 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-11T18:55:37+00:00Added an answer on June 11, 2026 at 6:55 pm

    You need to put single quotes around id and name. That is you need to replace this

    $id = $row[id];
    $name =$row[name];
    

    by this

    $id = $row['id'];
    $name =$row['name'];
    

    without knowing what’s in DB_CONNECT and what your error is this is my best guess at what’s wrong.

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

Sidebar

Related Questions

I have been trying to run a Avro map-reduce on oozie. I specify the
I've been trying to optimize a numeric program of mine, and have run into
Have been trying to encrypt an xml file to a string so that I
I have been trying to make custom radio buttons using HTML, CSS, and JavaScript.
I am relatively new to MySQL and PHP and I have been trying to
I have been trying to migrate a database from Sybase to MySQL. This is
I have a reasonably complex MySQL query being run on another developer's database. I
I'm trying to run a query on a table that we keep for transactions
I have been using the MySql Query Browser and [opinion]it has to be the
I am trying to write a Bash script to run a MySQL query from

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.