Page 1 of 1

database :(

Posted: Sun Dec 07, 2003 10:58 am
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 ??

Posted: Sun Dec 07, 2003 11:10 am
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]