I am constructing a form for a user to enter race results. the results are stored in a table called 'results', and i have two other tables, 'member' and 'race'(holding race name, race date, etc)
the results table requires the member_no and race_no (the primary keys from the other two tables, in results they are a composite key)
however obviously cant expect user to remember numbers,so i wanted to allow them to enter a members last name, then pull the member_no and assign it to a variable, do the same with the race_name and race_date to idenitify the race_no, then finally use those variables to insert the member_no and race_no into the results table along with the time.
im mega new to php and mysql, so i dont even know how to have drop downs or how to validate date and time entries so im stuck with the default YYYY-MM-DD and 00:00:00 🙁, but even this is not working- i can enter the data pefectly as shown in the mysql tables, but it keeps saying that the member AND race do not exist.
the code for getting the member_no from the last_name entered on the form and the race_no from the race_name and race_date entered on the form is
// make query to get the member_no
$query_memberno = "SELECT member_no FROM member WHERE last_name = '$ln'";
$member_result = mysql_query($query_memberno); // run the query
if($row['member_no'] == 0)
{
echo "Error: That member does not exist in the database, please try again.";
// return them to form
}
else
{
$row = mysql_fetch_assoc($member_result);
$member_no = $row['member_no'];
}
// make query to get the race_no
$query_raceno = "SELECT race_no FROM race WHERE race_name = '$rn' AND race_date = '$rd'";
$race_result = mysql_query($query_raceno); // run the query
if($row['race_no'] == 0)
{
echo "Error: That race does not exist in the database, please try again.";
// return them to form
}
else
{
$row = mysql_fetch_assoc($race_result);
$race_no = $row['race_no'];
}
is there anything wrong with this? it keeps automatically throwing the error straight away... i know this isnt a really good way to do this at all, but its all i can do , if you have any suggestions or links to similar improved examples i would be grateful, but i really want to know why the above will not work.. 😕
thanks!