Can´t get value of sum from a selected repeated id (PHP) and (MySQL)
===

I´m trying to get a sum from the column of the repeated values that was selected in a form before, but i can´t even show the result, is there something wrong with this code?

    <a href='verificar.dwt.php'>Voltar atrás</a>
    
    <div align="center"><? 
    
    include 'configmov.dwt.php'; 
    
    $tableName='movimentos';
    $matricula = mysql_real_escape_string($_POST['matricula']);
    
    $sql="SELECT matricula, marca, despesa FROM ".$tableName." WHERE matricula = '".$matricula."'";
    $result=mysql_query($sql); 
    
    $result1 = mysql_query('SELECT SUM(value) AS value_sum FROM despesa'); 
    $row1 = mysql_fetch_assoc($result1); 
    $sum = $row1['value_sum'];
    
    $n=1; 
    
    echo "Os seus resultados: <p>";
    
    echo "<table border=0>";
    echo "<tr bgcolor='#CCFFCC'>";
    echo "<td style='width: 100px;'>Matricula</td>";
    echo "<td style='width: 100px;'>Marca</td>";
    echo "<td style='width: 100px;'>Despesa</td>";
    echo "</tr>";
    
    
    
    
    while($row = mysql_fetch_array($result)){ 
        echo "<tr bgcolor='#CCCCCC'>";
        echo "<td style='width: 100px;'>".$row['matricula']."</td>";
        echo "<td style='width: 100px;'>".$row['marca']."</td>";
        echo "<td style='width: 100px;'>".$row['despesa']."</td>";
    	echo "</tr>";
    	
    	echo $sum;
    }