Re: Stopping Multiple Entries in mySQL DB
| From: | Chris Earle | Date: | Sat, 27 Jul 2002 19:33:56 +0000 |
| Subject: | Re: Stopping Multiple Entries in mySQL DB | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-109995@lists.php.net to get a copy of this message | ||
do that plus with your insert, just do "INSERT IGNORE ....".
"John Holmes" <holmes072000@charter.net> wrote in message
news:000001c2358a$bd729fc0$b402a8c0@mango...
> > I just want my Adding Into Database script to check if
> > the Name/Country already exists, and if it does, it
> > shouldn't be allowed.
> >
> > If some with
> > Name : Jackson
> > Country : USA
> > exists in my DB, no one with same name/country should
> > be able to add his name/country in the DB.
>
> Have your database handle that, not PHP.
>
> When you create your table, make the combo of Name and Country unique.
>
> CREATE TABLE your_table {
> Name VARCHAR(15),
> Country VARCHAR(15),
> UNIQUE Name_Country (Name, Country)
> }
>
> Then you can have "Jackson, USA", "Jackson, UK", "Someone Else,
> USA",
> etc...just not the same combination at all.
>
> ---John Holmes...
>