I am not sure what the problem here. But, looking at the code, check this lines:
if ( mysql_num_rows($result_content)==0){
$sql="INSERT INTO $table_group (first_name, last_name)VALUES('$first_name', '$last_name')"; }else { echo "Name already exists"; }
$result=mysql_query($sql);
the line:
$result=mysql_query($sql);
is outside the "if then else" loops which means, the query is always executed.
This is a problem if name already exists, because the string $sql is empty.
So, try moving the code inside the if then loop.
Good luck!