Brandon Garnett
asked on
Populate a textarea from a mysql database where field one is equals drop down value?
I would like to populate a text area with info stored in a MySql database. The catch is.. Well my problem is.. I have a drop down that pulls numbers from the database. This is kind of hard to explain..
Drop down is list of data in "roomnum" field. So if "roomnum" is equal to 555555 the populate textarea with "htmlcode" from same row.
So textarea would equal the htmlcode from the row where number 555555 was the data. I am confusing myself...
Drop down is list of data in "roomnum" field. So if "roomnum" is equal to 555555 the populate textarea with "htmlcode" from same row.
So textarea would equal the htmlcode from the row where number 555555 was the data. I am confusing myself...
<form method="post" action="/backoffice/editor/examples/dump2.php?content=" onsubmit="return validate_form(this)" name="formmy">
Choose Room: <select size="1" name="roomnum" id="roomnum" onchange="">
<?php
if ($_POST[roomnum] != "")
{
echo "<option>$_POST[roomnum]</option>";
echo "<option value=\"\"></option>";
}
else
{
echo "<option></option>";
}
//require the config file
require ("../../config.php");
//make the connection to the database
$connection = @mysql_connect("localhost", "root", "") or die(mysql_error());
$db = @mysql_select_db("pass")or die(mysql_error());
//build and issue the query
$sql ="SELECT roomnum FROM rooms WHERE roomnum != 'Template'";
$result = @mysql_query($sql,$connection) or die(mysql_error());
while ($sql = mysql_fetch_object($result))
{
$uname = $sql -> roomnum;
$beekeeper = $sql -> htmlcode;
echo "<option value=\"$uname\">$uname</option>";
}
?>
</select>
<?php
$formtest = 'roomnum';
$sql ="SELECT htmlcode FROM rooms WHERE roomnum = $formtest";
$result = @mysql_query($sql,$connection) or die(mysql_error());
while ($sql = mysql_fetch_object($result))
{
$uname = $sql -> roomnum;
$beekeeper = $sql -> htmlcode;
}
?>
<input type="button" value="Load Page" onClick="">
</p>
<textarea id="codeField" name="codeField" rows="30" cols="80" style="width: 100%" id="codeField">
<?php echo $beekeeper ?>
</textarea>
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
After adding herns tag and changing a few things it worked like a charm!
ASKER
A user selects a room number from the drop down. The room number equals one of the entries in the database. It compares the numbers selected with the database and matches it to the number in field (1) of row (whatever) when the match is made the textarea will be populated with field (2) of same row..