Jump to content


Photo

how to put output of query inside a form


  • Please log in to reply
2 replies to this topic

#1 dabbsy

dabbsy
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 27 September 2006 - 01:31 PM

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?

Code to pull back the application name
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.

Form code  (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

#2 jvrothjr

jvrothjr
  • Members
  • PipPipPip
  • Advanced Member
  • 300 posts
  • LocationOhio

Posted 27 September 2006 - 01:35 PM

your value is set to nothing to display the value you need to use

$_POST['varname']

<input type="text" name="app_name" size="25" maxlength="25" value="" />

If you understand everything you know nothing!

http://rcchjr.awardspace.com/

#3 dabbsy

dabbsy
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 27 September 2006 - 01:58 PM

The problem I'm having is with the syntax to drop into the form area - i.e. what I need to put into that value "" field.  I just can't work out how to get it into the form  :-[




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users