Jump to content

how to put output of query inside a form


dabbsy

Recommended Posts

This is probably bread and butter to you all, but I'm new to php, so you'll have to bear with me!!!

I've got a form which has several text areas in, which is defined within a form (a small part of the code is shown at the bottom) - I can happily get this to populate the database with new information using POST  - if (isset($_POST['submit'])).  The next stage is for the user to select an application name from a list (pulled back from the database) and include it in a form so the user can select from it.  The code for this is below.  Both pieces work individually, but I can't get the list of application to be displayed and work within a form.  Can anyone help with the syntax or am I approaching it in the wrong way?

[b]Code to pull back the application name[/b]
echo '<p><b>Select application:</b> <select name="app_name[]" size="3">';
$query = "SELECT application_id, application_name FROM contacts ORDER BY application_name ASC";
$result = mysql_query ($query);
// Run the query.
while ($row = mysql_fetch_array ($result, MYSQL_NUM))
{
echo '<option value=\"$row[0]\"';
echo ">$row[1]</option>\n'";
}
echo '</select></p>';
mysql_free_result ($result); // Free up the resources.

[b]Form code[/b]  (only one text field shown to avoid pasting a load of code)
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
    <p>
        Application Name:<br />
      <input type="text" name="app_name" size="25" maxlength="25" value="" />
    </p>
    <p>
    <p>
      <input type="submit" name="submit" value="Submit!" />
    </p>
</form>



Hope someone can help!
Thanks,
J
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.