Ideally, you would design your data differently:
Table
Test Scores
Test Number
Score
Student ID
Date.
Something like that.
Then you'd populate each row with the appropriate data.
As it is, with a table like this:
TestScores
test1
test2
test3
etc.
You are stuck adding many columns together
If that's your design, however,
You'd use
SELECT SUM(test1+test2+test3...
etc.
until you have all 21 columns with+ signs. Commas won't work; + signs will.
The SQL reserved word 'AS' means
'call this calculated field by this name.'
So if you say
$result=mysql_query("SELECT SUM(test1+test2) AS 'results'
FROM testtable");
$row=mysql_fetch_array($result);
You can refer to the value like this:
$row['results']
AS is optional; you could also say:
$result=mysql_query("SELECT SUM(test1+test2)
FROM testtable");
$row=mysql_fetch_array($result);
and simply refer to the returned value as $row[0];
NOTE THIS: Typically, you don't store/insert calculated values in a separate table. This can be a maintenance nightmare.
Example: you mismarked test 10 for student id 5....you'll have to update bot the test table and appropriate summary table.
Calculations done on the fly by MySQL are VERY fast, and generally its better to calculate on the fly rather than store.
It might be time to get a book on this stuff.