I have a basic web form that takes 3 inputs and inserts them into a database table. The DB set up:
    require_once 'MDB2.php';
    include "sql-connect.php";
    $host = 'host.yyy.uk';
    $dbName = 'user01';
    $dsn = "mysql://$username:$password@$host/$dbName"; 
    $db = &MDB2::connect($dsn); 
    if (PEAR::isError($db)) { 
        die($db->getMessage());
    }
    $db->setFetchMode(MDB2_FETCHMODE_ASSOC);
But even if the data is entered correctly into the DB and the data is inputted into the DB, php returns an error (Invalid query: Duplicate entry 'AAA123(ACode)' for key 'PRIMARY). This is my code for handling the form:
if (isset($_POST['submit'])) {
    $sql = "INSERT INTO MODULES (APart, ACode, ATitle) VALUES ('$_POST[APart]', '$_POST[ACode]', '$_POST[ATitle]')";
    mysql_query($sql);
    $endResult = mysql_query($sql);
    if (!$endResult) {
        $message  = 'Invalid query: ' . mysql_error() . "\n";
        $message .= 'Whole query: ' . $sql;
        die($message);
    }
}
 
     
     
    