I would like to link my HTML form and PHP script such that when a user passes values via the form they are processed by the PHP script and a relevant response given. My PHP script is as follows;
<?php //create server and database connection constants define ("DB_SERVER", "localhost"); define ("DB_USER","root"); define ("DB_PASSWORD",""); define ("DB_NAME", "project"); global $con; $con = new mysqli (DB_SERVER,DB_USER,DB_PASSWORD, DB_NAME); //Check server connection if ($con->connect_error){ die ("Connection failed:". $con->connect_error); }else { echo "Connected successfully <br />"; } // Calculating the attack stength function predictor ($home_team,$away_team){ global $con; $result=[0,0]; // For the home team $home_team_strength=get_query_value($con,"SELECT SUM(HTgoals)/Count(*) FROM `results` WHERE Home_team = '$home_team' "); $league_strength=get_query_value($con,"SELECT SUM(HTgoals)/Count(*) FROM `results`"); $home_team_attack_strength=$home_team_strength/$league_strength; $away_team_strength = get_query_value($con, "SELECT SUM(HTgoals)/Count(*) FROM `results` WHERE Away_team='$away_team'"); $away_team_defence_strength=$away_team_strength/$league_strength; $result[0]=$home_team_attack_strength*$away_team_defence_strength*$league_strength; // For the away team $away_team_strength_2 = get_query_value($con, "SELECT SUM(ATgoals)/Count(*) FROM `results` WHERE Away_team='$away_team'"); $league_away_strength=get_query_value($con, "SELECT SUM(ATgoals)/Count(*) FROM `results`"); $away_team_attack_strength =$away_team_strength_2/$league_away_strength; $home_team_defence =get_query_value($con, "SELECT SUM(ATgoals)/Count(*) FROM `results` WHERE Home_team='$home_team'"); $home_team_defence_strength =$home_team_defence/$league_away_strength; $result[1] = $away_team_attack_strength*$home_team_defence_strength*$league_away_strength; return $result; } function get_query_value ($con,$query){ $return_value=-1; $con->real_query($query); $result=$con->use_result(); $row=$result->fetch_row(); $result->close(); return $row[0]; }
My HTML form is below;
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Prediction</title> <form> <form action="predictor.php" method="POST"> <font color ="blue"> <div align="center"> <p> Please enter the teams you would like to view predictions for</p> <p> Enter the home team</p> Home_team:<select name = "Home_team"> <br> <option value = "Bandari">Bandari</option> <option value = "Chemelil">Chemelil</option> <option value = "Gor Mahia">Gor Mahia</option> <option value = "Kakamega Homeboyz FC" >Kakamega Homeboyz FC</option> <option value = "Leopards">Leopards</option> <option value = "Mathare Utd">Mathare Utd</option> <option value = "Muhoroni">Muhoroni</option> <option value = "Nairobi City">Nairobi City</option> <option value = "Rangers">Rangers</option> <option value = "Sony Sugar">Sony Sugar</option> <option value = "Sofapaka">Sofapaka</option> <option value = "Thika Utd">Thika Utd</option> <option value = "Tusker">Tusker</option> <option value = "Ulinzi Stars">Ulinzi Stars</option> <option value = "Ushuru">Ushuru</option> <option value = "Western Stima">Western Stima</option> </select><br><br> <p> Enter the away team</p> Away_team:<select name = "Away_team"><br> <option value = "Bandari">Bandari</option> <option value = "Chemelil">Chemelil</option> <option value = "Gor Mahia">Gor Mahia</option> <option value = "Kakamega Homeboyz FC" >Kakamega Homeboyz FC</option> <option value = "Leopards">Leopards</option> <option value = "Mathare Utd">Mathare Utd</option> <option value = "Muhoroni">Muhoroni</option> <option value = "Nairobi City">Nairobi City</option> <option value = "Rangers">Rangers</option> <option value = "Sony Sugar">Sony Sugar</option> <option value = "Sofapaka">Sofapaka</option> <option value = "Thika Utd">Thika Utd</option> <option value = "Tusker">Tusker</option> <option value = "Ulinzi Stars">Ulinzi Stars</option> <option value = "Ushuru">Ushuru</option> <option value = "Western Stima">Western Stima</option> <select><br><br> <td> <input type="submit" name="submit" value="Submit"/> </form>
Any ideas it is currently not working.