faqts : Computers : Programming : Languages : PHP : Database Backed Sites : MySQL

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

4 of 13 people (31%) answered Yes
Recently 3 of 10 people (30%) answered Yes

Entry

How can I restrict an INSERT if the two fields to be inserted exist?

Mar 12th, 2003 18:02
Alan, taylor gerring, Chris,


You must first perform a SELECT query to ensure that the fields don't 
exists.
-------------
Put something like this:
<?php
$result = mysql_query('SELECT blah FROM bleh WHERE blah LIKE "'.$_POST
["blah"].'"');
if (mysql_num_rows($result) == 1) {
	echo "Sorry! It already exists. Try again";
} else {
// The processing codes here
}
?>