autopopulate字段用javascript和mysql查询下拉列表

I have a question on how to autopopulate a dropdown menu from column in mysql database, then autofill fields below based upon the user's selection. Please help! My code wont post correctly. I know how to query database and populate the dropdown but i cant get the fields to autofill below.

<?php
if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";

mysql_close($con);
header("Location: dashboard.html")
?> 
<?php
$con = mysql_connect("localhost","root","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());

else { 
mysql_select_db("Transgen", $con);?>
$query = "SELECT * FROM PartnerSetup" or die(mysql_error()); 
$result = mysql_query($query) or die(mysql_error()); 

    if(mysql_num_rows($result) > 0) {
        while($row = mysql_fetch_assoc($result)) { 
            echo ($row['Partner']); echo "<br/>"; 
        } 
    ?>

Time to get cracking;

First is your errors within the code;

if (!mysql_query($sql,$con))

This should be handled within your database connection information:

Example:

$host = "HOST";
$Username = "user"; 
$Password = "password"; 
$sql = mysql_connect("$host", "$Username", "$Password");
$conn = mysql_select_db("DATABASENAME", $sql); // Depending on what $sql and $con contain on your code. 

Then your if statement:

if (!mysql_query($sql,$con)) {...}

Should be replaced by:

if (!($sql))
{
   die('Error: ' . mysql_error());
} // Kills the script if correct information could not be used to access the database

You have an echo

echo "1 record added";

Which is outside your brackets { or }

I am presuming this is inside either a function or a $_POST/$_GET If so, then ignore the above

If not, then your script will be echoing out that string without need. This should be revised

You have also prematurely closed your PHP tags after: mysql_select_db("Transgen", $con);?>

^ In addition; You have !$sql and !con prior to $sql being set; on the line:

$con = mysql_connect("localhost","root","password");

Which $con is stated after the initial variables, this might return an error if you not already have set $con and $sql prior to the first line displayed.

So your $query will not be executed, rather be shown in plain text to the user/person viewing the page.`

and in response to your question; if you are set on doing it through javascript, then look online.

This can be done through PHP by using a while loop with a few queries to populate your drop down menu within PHP it's self.

<select name="SELECTNAME"> 
    <?PHP
        $DropDownQuery = mysql_query("SELECT * FROM PartnerSetup");
        while ($Rows = mysql_fetch_array($DropDownQuery))
        {
            $Partner = $Rows['Partner'];
            echo "<option value=\"$Partner\">$Partner</option>";
        } // This will enable the user to submit a "partner" if needed in a <form> </form> setup
    ?>
    </select>

I would recommend appending errors within your code, I'm going by what has been submitted, and what I can see. From what I can see, I have pointed out areas that might/will return an error.

I would also look into the PDO functions; as MySQL is depreciated and will be removed from future PHP Revisions.