I am new to PHP and MySQL. I have looked all over for this and I still could not find anything so I wanted to know if anyone on here would be able to help me out. I want to make a website that allows a user to use a form, using HTML, to search a user's name and what exercise they want to do for a workout. Next, I want to output to the user what weight the user should use for their workout.
I already haves for men and women's bench, squat, and deadlift, so the problem is that I need the form to search the user's skill level, and based off that skill level, I want the table to output the correct weight the user should use. For example, if a user a male and a novice in say, bench press, the table that should be searched is benchmen and the weight of a novice who wants to do bench press is, say, 100 lbs. (This is an arbitrary number, but I want the actual value from my benchmen table to show up). This number that should show up is based on the user's skill level and their weight.
So to sum up, I am having trouble using a user table from a MySQL table, which I have already made, to search another table, called benchmen or benchwomen, etc. to output the desired weight from one of those tables based on the user's weight, sex, and skill. I currently cannot find anything that will do exactly what I want it to do online so if anyone has any insight please let me know. If there are any additional questions, please let me know. And sorry for the long post. I just wanted to be sure I was thorough in explaining what I meant.
Thank you in advance.
<?php
if(isset($_POST['username']) && isset($_POST['exercise']))
{
$con = mysqli_connect("localhost", "root", "", "database"); //Connect to the db
$stmt = mysqli_prepare($con, "SELECT skill, sex, weight FROM user WHERE username = ?"); //Make the query
mysqli_stmt_bind_param($stmt, "s", $_POST['username']); //Bind our inserted form username into the query
mysqli_stmt_execute($stmt); // Execute the query
mysqli_stmt_store_result($stmt);
if(mysqli_stmt_num_rows($stmt) == 0) //No rows found with that username
echo "Unable to find any skills with that username!";
mysqli_stmt_bind_result($stmt, $skill, $sex, $weight); //Bind our returned skill to $skill
mysqli_stmt_fetch($stmt); //Fetch the results
echo " The skill, sex, and weight of " . $_POST['username'] . " is: " . $skill, " " . $sex, " " . $weight; //Echo out our skill
//Test statement
echo "<br>";
echo $_POST['username'] . " wants to do: " .$_POST['exercise'];
}
?>
<h1>Username</h1>
<form name='' action='' method='post'>
Enter a Username<input type='text' name='username'><br>
Choose an Exercise: <input type="radio" name="exercise" value="Squat">Squat
<input type="radio" name="exercise" value="Bench">Bench Press
<input type="radio" name="exercise" value="Deadlift">Deadlift<br>
<input type='submit' value='Submit'>
</form>
Okay, here are some sample rows: I want it to output something like "Lmalamos should use the weight of 150 lbs for bench press" or something along those lines.
In this example, my user's weight is 150 lbs and he is an intermediate skill level, so the blue highlighted area should be output.
The way this works is the statement will look for the weight that is greater or equal to the first weight number, and less than the second weight number. 150 in this case, is greater than 145, but less than 155, so the table lookup will be under the rows with those weights.