I have a database table called packages which contains the various camera packages that we receive. I want to use this table to populate a drop down menu. When the package is selected and submitted, I would like the values in the form fields on the page to be populated with the values from the packages table (camera Model, camera bag model, Microphone model,etc.) I am fairly new to php, and I seem to be having some trouble with two queries on the same page.
<?php
require_once('Connections/info.php');
$sql = "SELECT * FROM packages";
$result = mysql_query($sql) or die(mysql_error());
$num_results = mysql_num_rows($result);
if (isset($_POST['Submit1']))
{
$uniqueID = $_POST['uniqueID'];
$sql = "SELECT * FROM packages WHERE uniqueID = $uniqueID";
$result2 = mysql_query($sql) or die(mysql_error());
}
?>
<html>
<head>
<title>Inventory</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
echo "<form name=\"dropdown\" method=\"post\" action=".$_SERVER['PHP_SELF']."><select name=\"uniqueID\">";
for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
echo "<option value=".$row['uniqueID'].">".$row['packageName']."</option>";
}
echo "</select>";
echo "<input type='hidden' name='dropdown' value='submit'>";
echo "<input type=\"submit\" name=\"Submit1\" value=\"Submit\"></form>";
?>
<form name="form1" method="post" action="<?php $_SERVER['PHP_SELF']?>">
<table width="300" border="1" cellspacing="0" cellpadding="0">
<tr>
<td>Camera Model</td>
<td><input name="cameraModel" type="text" id="cameraModel" value="<?php echo $_POST['cameraModel']?>" size="20" maxlength="20"></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</form>
</body>
</html>
If someone could give me some insight on how something like this would work I would really appreciate it.
Thanks
<?php
require_once('Connections/info.php');
$sql = "SELECT * FROM packages";
$result = mysql_query($sql) or die(mysql_error());
$num_results = mysql_num_rows($result);
if (isset($_POST['Submit1']))
{
$uniqueID = $_POST['uniqueID'];
$sql = "SELECT * FROM packages WHERE uniqueID = $uniqueID";
$result2 = mysql_query($sql) or die(mysql_error());
}
?>
<html>
<head>
<title>Inventory</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
echo "<form name=\"dropdown\" method=\"post\" action=".$_SERVER['PHP_SELF']."><select name=\"uniqueID\">";
for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
echo "<option value=".$row['uniqueID'].">".$row['packageName']."</option>";
}
echo "</select>";
echo "<input type='hidden' name='dropdown' value='submit'>";
echo "<input type=\"submit\" name=\"Submit1\" value=\"Submit\"></form>";
?>
<form name="form1" method="post" action="<?php $_SERVER['PHP_SELF']?>">
<table width="300" border="1" cellspacing="0" cellpadding="0">
<tr>
<td>Camera Model</td>
<td><input name="cameraModel" type="text" id="cameraModel" value="<?php echo $_POST['cameraModel']?>" size="20" maxlength="20"></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</form>
</body>
</html>
If someone could give me some insight on how something like this would work I would really appreciate it.
Thanks