database :(

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
pink
Forum Newbie
Posts: 3
Joined: Tue Dec 02, 2003 2:24 pm

database :(

Post by pink »

hi every one :)
i'have a problem again :(
i have entered a number in some feild in my website
and i want to save it to my database but before i want to check if there is a dublicate or not so if the number found it dosn't save it & tell me there
there is a dublicate & dosent save the number & ask me again to enter a new number ??
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

just get the field and check it.

Code: Select all

$sql="select field from table";
$result=mysql_query($sql);
$row=mysql_fetch_assoc($result);
if ($row['field'] == $_POST['my_var'])
{
   echo $_POST['my_var'].' is already in the database.  Please try again..';
   exit;
}

// otherwise, do other stuff...
[Edited: Matching the fieldnames to lessen confusion. --JAM]
Post Reply