Results 1 to 1 of 1

Thread: Populate a Text field via MYSQL Drop Down

  1. #1
    Join Date
    Feb 2009
    Thanked 0 Times in 0 Posts

    Default Populate a Text field via MYSQL Drop Down

    Hi All,

    I'm quite new to PHP/MySQL and I'm trying to create a Job Card for our company. I have created a page with a MySQL/PHP dropdown which works great, but I need to populate the text box with the dropdown selection.

    I have found a few examples using Javascript, but none of them seems to work. Am I doing something wrong or missing something. Below is my code:

    <title>Job Card</title>
    <script language=Javascript>
    function Choice()
    form1.users2.value = form1.users.value;
    // Make Connection
    include 'dbconfig.php';
    // Retreive data from database
    mysql_connect($dbhost2, $dbuser2, $dbpass2) or die(mysql_error());
    mysql_select_db($dbname2) or die(mysql_error());
    $user_query = "SELECT concat(first_name, ' ', last_name) as fullname FROM users ORDER BY first_name";
    $user_result = mysql_query($user_query);
    $client_query = "SELECT name FROM accounts ORDER BY name";
    $client_result = mysql_query($client_query);
    <Form name ="form1" Method ="POST" Action ="submitform.php">
    <p>Please Select a User:<br>
    <Select Name = "users" onChange='Choice();'>User Name:</Option>
    while ($row = mysql_fetch_array($user_result))
    echo '<Option value="'.$row['id'].'">'.$row['fullname'].'</Option>';
    <p><Input Type ="text" id="users2" name="users2">
    <p><Input Type ="Submit" Value ="Submit" Name ="submit" >
    Last edited by xChAMaRx; 02-16-2009 at 12:39 PM.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts