Ok I'm working on a script for my website and I've run into a problem. I have "competitors" and each "competitor" has players that are listed under them. Each player that the "competitor" has will have 4 stats that will be added up as a total score. This is where the problem comes in. I was wondering if there is a way to add up the 4 stats and put them together for a total score before the row is added to MySql. I've tried using $stats_total = $stats_1 + $stats 2. But that doesn't work when I try to put the value for an input in a form to be $stats_total. Anyone have any suggestions?

    Show some code. Lets see where you are right now. Could be a real simple thing you're missing...

      isnt the SQL something like:

      SELECT ADD(col1,col2,col3,coln) as colname FROM table

      ?

        <?php
        include_once'configstats.php';
        if($_POST['stats_competitor'] && $_POST['stats_player'] && $_POST['stats_rebounds'] && $_POST['stats_assists'] && $_POST['stats_blocks'] && $_POST['stats_steals'] && $_POST['stats_points'] && $_POST['stats_total']) { 
            $query = mysql_query("INSERT INTO $sqlTable VALUES(0, '".$_POST['stats_competitor']."', '".$_POST['stats_player']."', '".$_POST['stats_rebounds']."', '".$_POST['stats_assists']."', '".$_POST['stats_blocks']."', '".$_POST['stats_steals']."', '".$_POST['stats_points']."', '".$_POST['stats_total']."')"); 
            print "<br><br><a href='adminmain.php'>Back</a>";
        include_once "footer.php";
            exit; 
        }
        echo '<form action="addpoints.php" method="post">
          <table width="600" border="1" cellspacing="0" cellpadding="1">
          	<tr>
        	  <td>Competitor Name:<input type="text" name="stats_competitor" size="20"></td>
        	</tr>
        	<tr>
        	  <td>Player Name:<input type="text" name="stats_player" size="20"></td>
        	</tr>
            <tr> 
              <td>Rebounds</td>
              <td>Assists</td>
              <td>Blocks</td>
              <td>Steals</td>
              <td>Points</td>
              <td>Total Score</td>
            </tr>
            <tr> 
              <td><input type="text" name="stats_rebounds" size="20"></td>
              <td><input type="text" name="stats_assists" size="20"></td>
              <td><input type="text" name="stats_blocks" size="20"></td>
              <td><input type="text" name="stats_steals" size="20"></td>
              <td><input type="text" name="stats_points" size="20"></td>';
        $stats_rebounds = stats_rebounds;
        $stats_assists = stats_assists;
        $stats_blocks = stats_blocks;
        $stats_steals = stats_steals;
        $stats_points = stats_points;
        $stats_total = $stats_rebounds + $stats_assists + $stats_blocks + $stats_steals + $stats_points;
        echo '<td><input type="text" name="stats_total" size="20" value="$stats_total"></td>
            </tr>
            <tr>
              <td><input type="submit" name="submit" value="Submit"></td>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
            </tr>
          </table>  
        <br> </form>'; ?>

        That is the basic script.

          $stats_rebounds = stats_rebounds; 
          $stats_assists = stats_assists; 
          $stats_blocks = stats_blocks; 
          $stats_steals = stats_steals; 
          $stats_points = stats_points; 
          $stats_total = $stats_rebounds + $stats_assists + $stats_blocks + $stats_steals + $stats_points; 

          This whole part doesn't make sense. First, those aren't variables. Second, you need to submit the form before you can do the calculation.

            yeah so how/where would I put the information so it adds it all together and puts it as the total?

              Somewhere on addpoints.php

              It has to get the info before it can add it up

                Write a Reply...