0

I have this form and this function for insert name in db:

<form action="player.php#insertPlayer" method="post">
    <input type="text" name="nameplayer" />
    <input type="submit" value="Ajouter joueur" />
</form>

function insertPlayer($name) {
    db connection
    if (empty ($name))
        {echo "<span style='color: red'>WRONG!!!!</span>";}
    else
    {
        $insertplayer="INSERT INTO `player`(id, name) VALUES ('','$name');";
        echo 'player insert succes';
        mysql_close($db);
    }

}

But if i enter 2 same name, it's work, how can i do for just have always one same name ?

user3414480
  • 105
  • 1
  • 2
  • 7

1 Answers1

0

To make player table column name as UNIQUE, run the below ALTER statement on your corresponding Database.

ALTER TABLE player ADD UNIQUE (name);

If already the player table has some data with duplicate values in name column, the alter statement will fail. So clear the data from player table before running the ALTER statement.

Sreejith K
  • 76
  • 4