Error before i press submit

When I open this page I get error messages.

Thank you

( Warning : Trying to access array offset on value of type null in /home/sites/5a/8/83a6433687/public_html/ChampionshipGolf/results.php on line 88)

until I select an option on my form and press submit then works with no errors.




  $error = "";

  $Name = "";


    $name = $_POST['name']; 

$query = "SELECT COUNT(`Position`) AS 'position'  FROM scores where `name` = $name and Position = 1";

  $queryResults = mysqli_query($con, $query);

  $rowName = mysqli_fetch_array($queryResults);

  $query2 = "SELECT COUNT(`Position`) AS 'position2'  FROM scores where `name` = $name and Position = 2";

  $queryResults2 = mysqli_query($con, $query2);

  $rowName2 = mysqli_fetch_array($queryResults2);

  $query3 = "SELECT COUNT(`Position`) AS 'position3'  FROM scores where `name` = $name and Position = 3";

  $queryResults3 = mysqli_query($con, $query3);

  $rowName3 = mysqli_fetch_array($queryResults3);

     if($name == 1){

        $Name = "Kevin";

    } else if($name == 2){

        $Name = "Al";

    }else if($name == 8){

        $Name = "Lee";



    //echo $player."<br/>".$date."<br/>".$score."<br/>".$position."<br/>".$venue;

   $Query = "SELECT SUM(score)/COUNT(`name`) AS 'Average'  FROM scores where `name` = 1";

  $kevResults = mysqli_query($con, $Query);

  $row = mysqli_fetch_array($kevResults);

  $QueryAl = "SELECT SUM(score)/COUNT(`name`) AS 'AverageAl'  FROM scores where `name` = 2";

  $alResults = mysqli_query($con, $QueryAl);

  $rowAl = mysqli_fetch_array($alResults);

  $QueryLee = "SELECT SUM(score)/COUNT(`name`) AS 'AverageLee'  FROM scores where `name` = 8";

  $leeResults = mysqli_query($con, $QueryLee);

  $rowLee = mysqli_fetch_array($leeResults);

?><!doctype html>

<html lang="en">


    <!-- Required meta tags -->

    <meta charset="utf-8">

    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- Bootstrap CSS -->

    <link href="[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BmbxuPwQa2lc/FVzBcNJ7UAyJxM6wuqIj61tLrc4wSX0szH/Ev+nYRRuWlolflfl" crossorigin="anonymous">




    <h1>Total Averages in Championship of World</h1>

    <p> Kevin's average score : <?php echo $row['Average'] ?> </p><br>

    <p> Al's average score : <?php echo $rowAl['AverageAl'] ?> </p> <br>

    <p> lee's average score : <?php echo $rowLee['AverageLee'] ?> </p><br>

    <div id="formDiv">

<form method="POST" action="results.php" enctype="multipart/form-data">

    <h3>Choose player to find where you finished from all rounds<h3>

    <select name="name" class="form-select" aria-label="Default select example">


  <option value="1">kevin</option>

  <option value="2">al</option>

  <option value="8">lee</option>


    <button name="submit" type="submit" class="btn btn-dark">Submit</button>



<p>How many 1st's for <?php echo $Name ?> is <?php echo $rowName['position'] ?></p> <br>

<p>How many 2nd's for <?php echo $Name ?> is <?php echo $rowName2['position2'] ?></p> <br>

<p>How many 3rd's for <?php echo $Name ?> is <?php echo $rowName3['position3'] ?></p> <br>

    <script src="[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-b5kHyXgcpbZJO/tY9Ul7kGkf1S0CWuKcCD38l8YkeH8z8QjE0GmW1gYU5S9FOnJ0" crossorigin="anonymous"></script>




First you should never show errors on a production website.

Second, why don’t you just Fetch ALL the data at one time and just figure out the leaders from an array as you can easily do it with an array as you can do it with a database table? It would be much simpler. I do that with high score table for a trivia game that I developed. Just my opinion.

Thank you, I’ll have a look I’m learning PHP, sql, html and everything else from scratch, and I’m using the Web page for developing production itsjust a way to see how it’s developing and share progress with my two friends and I did not want yo show the error, that was why I asked for help.

Was not aware I could work out all sums (work out averages and count how many times a player had finished) from one table.

More googling needed, this site is my first time playing with sql and queries

Sponsor our Newsletter | Privacy Policy | Terms of Service