加分再显示余额

Adding points and then show balance

我的网站上有类似的东西。我想计算索菲亚的全部积分并向她展示总余额。这是 163。但我不知道如何添加,然后在我的网站上显示她的余额。对不起,如果这个问题太简单了。我是 php.

的新手

这是代码

     <form method="POST">
            user name : <input type="text" name="username"><br>
            Points to Add: <input type="number" name="blance" max="100" 
     min="1">
            <br> 
            <input type="submit" name="submit">
        </form>
 <?php 

   if (isset($_POST['submit'])) {

    $servername  = "localhost";
    $user = "root";
    $password = "";
   $database = "enter code here";

   $con = mysqli_connect("$servername", "$user" , "$password" , 
 "$database");

    if ($con->connect_error) {
    die ("connection failed" . $con->connect_error);
    } else {

   $username = mysqli_real_escape_string($con, $_POST['username']);
    $blance = mysqli_real_escape_string($con, $_POST['blance']);

      $sql = "INSERT INTO user (username, blance) VALUES ('$username', 
   '$blance')";

   if ($con->query($sql) === TRUE) {
    echo "success";
  } else {
 echo "error" . $sql . "<br>" . $con->error;
 }


  $sql6 = "SELECT * FROM user";
 $result = mysqli_query($con, $sql6);
 $resultcheck = mysqli_num_rows($result);

 if ($resultcheck > 0) {
   while ($row = mysqli_fetch_assoc($result)) {
    echo $row['username'] . "<br>";
    }
 }
   echo "<br>" . "<br>" . "<br>";



    }}

  ?>

</body>

假设您的 table 名为 test

,此查询将 return 每个用户名的分数总和
SELECT SUM(points) AS total_points
FROM test
GROUP BY username