Im trying to create an input form and Im getting stuck on a drop menu for a form. This is a very "generic" form so Im hoping someone can help me. Below is my coding on my current page:
<html>
<body>
<?php
if ($submit) {
// process form
$db = mysql_connect("localhost", "root"
mysql_select_db("accessories",$db);
$sql = "INSERT INTO accessory (item,snumber,userId) VALUES ('$item','$snumber','$userId')";
$result = mysql_query($sql);
echo "Thank you! Information entered. Click <a href=index.php>here</a> to view list.\n";
} else{
// display form
?>
<form method="post" action="<?php echo $PHP_SELF?>">
<table width=40%><tr><td>Item:</td><td><input type="Text" name="item" size="25" maxlength="50"></td></tr>
<tr><td>SN Number:</td><td><input type="Text" name="snumber" size="25" maxlength="50"></td></tr>
<tr><td>On Loan to:</td><td>
<select name="userId">
<?php
$connection=mysql_connect("localhost", "root"
$query="select userId, name from user";
$result2=mysql_db_query($query, "accessories", $connection);
while($row=mysql_fetch_array($result2))
{
$id=$row['userId'];
$name=$row['name'];
echo("<option value=\"$id\">$name</option>"
}
?>
</select>
</</td></tr></table>
<input type="Submit" name="submit" value="Enter information">
</form>
<?php
} // end if
?>
</body>
</html>
Currently the Loan to Select fields (options) are showing nothing (its not accessing the users in the user database)
My user database has this in its table:
userId (incremental)
name (name of user)
The accessory database has this in its table:
accessId (incremental)
item (items name)
date (date purchased)
snumber (serial number of item)
userId (this will reference the number in the user database)
So im trying to get the drop down menu pull from the user database by User Id but display the NAME of the user instead.
So when its shown on the index page, it will display the items' information along with the person its on loan to.
for the index page, I currently have:
<html>
<body>
<?php
$db = mysql_connect("localhost", "root"
mysql_select_db("accessories",$db);
$result = mysql_query("SELECT * FROM accessory",$db);
if ($myrow = mysql_fetch_array($result)) {
echo "<table border=1 width=100%>\n";
echo "<tr><td>Item</td><td>Date Purchased</td><td>SN Number</td><td>On Loan to</td></tr>\n";
do {
printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\n", $myrow["item"], $myrow["date"], $myrow["snumber"], $myrow["name"]);
} while ($myrow = mysql_fetch_array($result));
echo "</table>\n";
} else {
echo "Sorry, no records were found!";
}
?>
</body>
</html>
On Loan to is blank because I can't figure out how to display the information from Accessory database (userId) in the table.
How do I get the index page to show the ITEMS (all info from accessory table) along with the person its on loan to (not by userId number but by name instead), and how do I get the form in insert.php to include the User list from the user table in the database?
<html>
<body>
<?php
if ($submit) {
// process form
$db = mysql_connect("localhost", "root"
mysql_select_db("accessories",$db);
$sql = "INSERT INTO accessory (item,snumber,userId) VALUES ('$item','$snumber','$userId')";
$result = mysql_query($sql);
echo "Thank you! Information entered. Click <a href=index.php>here</a> to view list.\n";
} else{
// display form
?>
<form method="post" action="<?php echo $PHP_SELF?>">
<table width=40%><tr><td>Item:</td><td><input type="Text" name="item" size="25" maxlength="50"></td></tr>
<tr><td>SN Number:</td><td><input type="Text" name="snumber" size="25" maxlength="50"></td></tr>
<tr><td>On Loan to:</td><td>
<select name="userId">
<?php
$connection=mysql_connect("localhost", "root"
$query="select userId, name from user";
$result2=mysql_db_query($query, "accessories", $connection);
while($row=mysql_fetch_array($result2))
{
$id=$row['userId'];
$name=$row['name'];
echo("<option value=\"$id\">$name</option>"
}
?>
</select>
</</td></tr></table>
<input type="Submit" name="submit" value="Enter information">
</form>
<?php
} // end if
?>
</body>
</html>
Currently the Loan to Select fields (options) are showing nothing (its not accessing the users in the user database)
My user database has this in its table:
userId (incremental)
name (name of user)
The accessory database has this in its table:
accessId (incremental)
item (items name)
date (date purchased)
snumber (serial number of item)
userId (this will reference the number in the user database)
So im trying to get the drop down menu pull from the user database by User Id but display the NAME of the user instead.
So when its shown on the index page, it will display the items' information along with the person its on loan to.
for the index page, I currently have:
<html>
<body>
<?php
$db = mysql_connect("localhost", "root"
mysql_select_db("accessories",$db);
$result = mysql_query("SELECT * FROM accessory",$db);
if ($myrow = mysql_fetch_array($result)) {
echo "<table border=1 width=100%>\n";
echo "<tr><td>Item</td><td>Date Purchased</td><td>SN Number</td><td>On Loan to</td></tr>\n";
do {
printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\n", $myrow["item"], $myrow["date"], $myrow["snumber"], $myrow["name"]);
} while ($myrow = mysql_fetch_array($result));
echo "</table>\n";
} else {
echo "Sorry, no records were found!";
}
?>
</body>
</html>
On Loan to is blank because I can't figure out how to display the information from Accessory database (userId) in the table.
How do I get the index page to show the ITEMS (all info from accessory table) along with the person its on loan to (not by userId number but by name instead), and how do I get the form in insert.php to include the User list from the user table in the database?