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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:26:44+00:00 2026-06-12T05:26:44+00:00

I have a HTML form that has a selection drop down. I would like

  • 0

I have a HTML form that has a selection drop down. I would like to populate the drop down from my MySQL DB. The HTML form already has some java scripts to handle datepicker, and current date on one of the fields in the form.

I can code the form for the selection manually, but would like it to come from MySQL. the php I am using I put in it’s own file name.php to make sure it worked correctly. I added some echo statements in the php to build the form, and the selection, and then populate the selection, and close it. this worked just fine as a standalone php.

When I append the php in the form under the selection definition, it does not populate the selection at all, it is left blank/empty. If I add some echo statments to output info in the format of a selection option, the first echo never shows up, and the subsequent echos show up, but any variable show up as the variable name.

<form id="form1" name="form1" method="post" action="/db_log.php">
Field:<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);

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

</select><br />
</form>

the above yealds an empty select dropdown.
But this works great as a PHP file.

<?php
echo "<form id=\"form1\" name=\"form1\" method=\"post\" action=\"/db_log.php\">";
    echo "Select:<select name=\"id\">";
    require_once dirname(__FILE__) . '/db_connect.php';
$db = new DB_CONNECT();

$result=mysql_query("SELECT id, name FROM file order by name");

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

    echo "</select><br />";
    echo "</form>";
?>

If I add a echo to the HTML form one like a test echo before any other echo, it is ignored.

<form id="form1" name="form1" method="post" action="/db_log.php">
Field:<select name="id">

<?php
  echo "<option value=\"1\"> Test-name </option>";

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

$query="SELECT id, name FROM file order by name";
$result=mysql_query($query);

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

</select><br />
</form>

the only thing that shows up from this is the option to select $name

  • 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-12T05:26:45+00:00Added an answer on June 12, 2026 at 5:26 am

    Based on this question and the previous questions and the comments you’ve gotten and made I’m going to guess that you’re trying to run php from a .html file. You need to save your code (including the html) in a .php file for it to work.

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

Sidebar

Related Questions

I have a HTML form that has certain fields which i am opening inside
I have a webrequest that returns a html response which has form inside with
I have an HTML form that needs multiple submit buttons, like this: <input type=submit
I have a simple html form that looks like the following <form action=search.php method=get>
I have a simple html form that is structured something like this: <form name=test
(I'm fairly new to jQuery.) I have a traditional HTML form with 3 drop-down
I have a simple form that has a list (dropdown list generated from a
I have a form that has several drop downs, when one is chosen, it
I have a following problem, I have HTML form that uploads a file with
I have a HTML form that accepts a comma separated list of tags, which

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.