Hi. I have three input fields in this form. I want the second (X10 Channel) to be a drop down box with a cross table query drawing the field x10_channel from a table called devices. I don't know how to make the chosen value from the drop down be submitted with the other two inputs and entered in this table (commands). Thanks very much in advance. The full code so far is:
<html><head><title>Add a Command</title></head>
<body>
<?php
session_start();
if (!isset($_SESSION['user'])
|| $_SESSION['user'] !== true)
{
header('Location: login.php');
exit;
}
$query = "LOCK TABLES Class WRITE, Student WRITE";
mysql_query($query);
$self = $_SERVER['PHP_SELF'];
$commandID = $_POST['commandID'];
$x10_channel = $_POST['x10_channel'];
$x10_command = $_POST['x10_command'];
if( (!$commandID) or (!$x10_channel) or (!$x10_command) )
{
$form ="<table width=\"267\" border=\"1\" align=\"center\" cellpadding=\"1\" cellspacing=\"1\" bordercolor=\"#000000\">";
$form.="<tr bgcolor=\"#CCCCCC\"><td colspan=\"2\"><font size=\"1\" face=\"Verdana\"><center>";
$form.="Please enter details of your new Command";
$form.="</td></font>";
$form.="</tr><tr>";
$form.="<td><font size=\"2\" face=\"Verdana\"><form action=\"$self\"";
$form.=" method=\"post\">Command Word:</td>";
$form.="<td><input type=\"text\" name=\"commandID\"";
$form.=" value=\"$commandID\"></td></tr><tr><td><font size=\"2\" face=\"Verdana\">X10 Channel:</td>";
$form.="<td><input type=\"text\" name=\"x10_channel\"";
$form.=" value=\"$x10_channel\"></td></tr><tr><td><font size=\"2\" face=\"Verdana\">X10 Command:</td>";
$form.="<td><input type=\"text\" name=\"x10_command\"";
$form.=" value=\"$x10_command\">";
$form.="<tr><td colspan=\"2\"><center><input type=\"submit\" value=\"Add Command\">";
$form.="</tr></table></form>";
echo($form);
}
else
{
$conn = @mysql_connect("localhost","alexm","rugby")
or die("Could not connect to MySQL");
$db = @mysql_select_db("rugby_project",$conn)
or die("Could not select Database");
$sql = "insert into commands (commandID,x10_channel,x10_command)
values (\"$commandID\",\"$x10_channel\",\"$x10_command\")";
$result = @mysql_query($sql,$conn)
or die("Could not execute query - this command name already exists or this X10_command has already been taken - View your commands table to check this");
if($result)
{
echo( "<table width=\"30%\" border=\"1\" align=\"center\" cellpadding=\"4\" cellspacing=\"1\" bordercolor=\"#000000\">
<tr bgcolor=\"#CCCCCC\">
<td colspan=\"2\"><font size=\"1\" face=\"Verdana\">
<center>The command $commandID has now been added to the Database</center></font></td></tr></table><p><font size=\"1\" face=\"Verdana\"><center><a href=\"addcommand.php\">Add More</a><p>" );
}
}
$query = "UNLOCK TABLES";
mysql_query($query);
?><p>
<font size="1" face="Verdana"><center>
<a href="javascript:history.go(-1)">Return to Control Panel</a> |
<a href="logout.php">Log out</a>
</body></html>