I am quite new at this and was hoping for some help. I am trying to add a record to a db table (results) using form dropdown lists from two other tables (teams & tournaments). Here is what I have so far:
insert.php
<html>
<head><title>Database Update</title>
</head>
<body>
<h1 align="center">Weekenders Bass Club<br>
Tournament Results <br>
Update System</h1>
<p align="center"> </p>
<?
$dbh=mysql_connect ("localhost", "xxxxx", "xxxxx") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("xxxxx");
?>
<?
$SQL = "SELECT FROM teams";
$RESULT = mysql_query($SQL,$dbh) OR die ("Query failed 1");
$SQL1 = "SELECT FROM tournaments";
$RESULT1 = mysql_query($SQL1,$dbh) OR die ("Query failed 1");
?>
<p align="center"> Add Tournament Results </p>
<FORM METHOD='post' ACTION='insertresults.php'>
<p align="center">
<SELECT NAME="team">
<OPTION VALUE="0" SELECTED>--- Select Team ---</OPTION>
<?PHP
while ($ROW = mysql_fetch_array($RESULT))
{
$team = $ROW["team"];
echo "<OPTION >$team</OPTION>";
}
?>
</SELECT>
<SELECT NAME="tournament">
<OPTION VALUE="0" SELECTED>--- Select Tournament---</OPTION>
<?PHP
while ($ROW = mysql_fetch_array($RESULT1))
{
$tournament = $ROW["tournament"];
echo "<OPTION >$tournament</OPTION>";
}
mysql_close($dbh);
?>
</SELECT>
</p>
<p align="center">Enter # of Fish
<input type="text" name="#offish">
Enter Total Weight
<input type="text" name="weight">
Enter Lunker
<input type="text" name="lunker">
<BR>
<BR>
<INPUT TYPE='SUBMIT' VALUE='Submit Results!'>
<INPUT TYPE='RESET' VALUE='Start Over'>
</p>
</FORM>
<p align="center"> Add New Team </p>
<form action="insertteam.php" method="POST">
<p align="center">Enter New Team:
<input type="text" name="team">
<input type="submit" value="Submit Team">
<INPUT TYPE='RESET' VALUE='Start Over'>
</p>
</form>
<p align="center"> Add New Tournament </p>
<form action="inserttournament.php" method="POST">
<div align="center">Enter New Tournament:
<input type="text" name="tournament">
<input type="submit" value="Submit Tournament">
<INPUT TYPE='RESET' VALUE='Start Over'>
</div>
</form>
<p> </p>
</body>
</html>
insertresults.php
<html>
<head><title>Insert Results</title>
</head>
<body>
<?
$dbh=mysql_connect ("localhost", "xxxxx", "xxxxx") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("xxxxxx");
$tournament = $POST['tournament'];
$offish = $POST['#offish'];
$weight = $POST['weight'];
$lunker = $POST['lunker'];
$sql = "INSERT INTO results (tournament, #offish,weight,lunker) " .
"VALUES ('$tournament', '$#offish', '$weight', '$lunker')";
$sql_result = mysql_query($sql,$dbh) or die ('Could not insert data');
echo('Data inserted successfully');
mysql_close($dbh);
?>
</body>
</html>
Thanks in advance for your help...