Jump to content

PHP Soccer League - Not sure what next?


Coders2018

Recommended Posts

Hello,

 

I'm fairly new to PHP and I'm still strolling through my book that I purchased, but I thought what I've learned already I'll put into practice by creating a PHP Soccer League.

 

I've decided for some reason to do the part where you enter the results in firstly. All this works perfectly and here is the code for that:

 

The HTML:

<html>
    <head>
        <title>League Results</title>
    </head>
<body>
              <center>
              
           <form action="view_scores.php" method="post">

                  <select name="TeamName">
    
                              <option value="Arsenal">Arsenal</option>
                              <option value="Manchester United">Manchester United</option>
                              <option value="Chelsea">Chelsea</option>
                              <option value="Tottenham">Tottenham</option>

                  </select>  

                  <select name="score">
    
                              <option value="0">0</option>
                              <option value="1">1</option>
                              <option value="2">2</option>
                              <option value="3">3</option>
                              <option value="4">4</option>
                              <option value="5">5</option>
                              <option value="6">6</option>
                              <option value="7">7</option>
                              <option value="8">8</option>
                              <option value="9">9</option>
                              <option value="10">10</option>
                    
                  </select>
                    
                    
   -   

                  <select name="awayscore">
    
                              <option value="0">0</option>
                              <option value="1">1</option>
                              <option value="2">2</option>
                              <option value="3">3</option>
                              <option value="4">4</option>
                              <option value="5">5</option>
                              <option value="6">6</option>
                              <option value="7">7</option>
                              <option value="8">8</option>
                              <option value="9">9</option>
                              <option value="10">10</option>
                    
                  </select>  


                  <select name="AwayTeam">
         
                              <option value="Arsenal">Arsenal</option>
                              <option value="Manchester United">Manchester United</option>
                              <option value="Chelsea">Chelsea</option>
                              <option value="Tottenham">Tottenham</option>
        
                  </select>   


            <input type="submit" name="enter_scores" value="Enter Scores"> 

           </form>

</body>

</html>

 

The PHP:

<?php

    $home_team_name = $_POST['TeamName'];
    $score = $_POST['score'];
    $awayscore = $_POST['awayscore'];
    $away_team_name = $_POST['AwayTeam'];

echo '<center>'. $home_team_name. str_pad($spaces, 4). $score. str_pad($spaces, 4).

   $hyphen = "-".str_pad($test, 4). $awayscore. str_pad($test, 4). $away_team_name. str_pad($test, 4). '</center>' ;

            if($score > $awayscore) {
    
            echo $home_team_name. str_pad($spaces, 4). +3;

}


?>

 

These scripts may look very simple and there maybe more advanced ways to write them but I've not got that far in my book yet.

 

Next I want to display a league table now which resembles these results when they are entered this is where I'm stuck.

 

Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/206911-php-soccer-league-not-sure-what-next/
Share on other sites

You're going to need to store the results in a database and then retrieve the data from it into a table. Your setup now just has you putting a score into a form and submitting it to the next page where it will display it, but the second you leave that page the data is gone.

Thanks for that.

 

I've now re-written my PHP script so that it will add the team names to the correct field in the database but for some reason it doesn't work.

 

This is what the PHP script looks like now:

 

<?php

    // Database Connection Information
    
    $username = "MY_USERNAME";
    $password = "MY_PASSWORD";
    $database = "MY_DATABASE_NAME";
    
    //Variables passed from the HTML Form
    
    $home_team_name = $_POST['TeamName'];
    $score = $_POST['score'];
    $awayscore = $_POST['awayscore'];
    $away_team_name = $_POST['AwayTeam'];
    
    
    // Connect to the database
    mysql_connect(localhost, $username, $password);
    @mysql_select_db($database) or die ("Unable to connect to the database provided");
    

   $query = "INSERT INTO team WHERE Name VALUES ('','$home_team_name','$away_team_name')";
   
   
   mysql_query($query);

   mysql_close();


?>

 

Any help would be greatly appreciated.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.