How do I check for a unqiue recording before trying to insert into a MySQL DB. I the record is already there, I want to throw back a message indicating so.
::rayfusion::
Check for unique record before inserting.
Moderator: General Moderators
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Code: Select all
<?php
$dbconn = mysql_connect($host, $user, $pass) or die(mysql_error());
mysql_select_db($db);
$sql = "SELECT field FROM table WHERE field='$input'";
$result = mysql_query($sql) or die(mysql_error());
if (mysql_num_rows($result) > 0) {
echo 'nope that's already in there';
} else {
// do what you want to do if the thing is unique
}
mysql_close();
?>Mac