MySQL UPSERT (Insert or Update)


     $sql = "INSERT INTO postcode
                        (postcode,
                         lat,
                         lon,
                         osEasting,
                         osNorthing,
                         osRef6)
                        VALUES ('" . str_replace(" ", "", $data[0]) . "',
                                '" . round($lat,6) . "',
                                '" . round($lon,6) . "',
                                '" . round($data[2]) . "',
                                '" . round($data[3]) . "',
                                '" . $osref . "'
                                )
                        ON DUPLICATE KEY UPDATE
                                postcode   = '" . str_replace(" ", "", $data[0]) . "',
                                lat        = '" . round($lat,6) . "',
                                lon        = '" . round($lon,6) . "',
                                osEasting  = '" . round($data[2]) . "',
                                osNorthing = '" . round($data[3]) . "',
                                osRef6     = '" . $osref . "'";