See what the following does for you. You will need to edit the INSERT query with the correct information before testing it.
if($id = mysql_fetch_assoc($rs))
{
// information already exists so let the user know
}
else
{
$q = "INSERT INTO `relationships` ....";
$rs = mysql_query($q) or die(mysql_error());
}
After you execute the query, assuming it is executed, you have to fetch the data. In my example, $id with be null or it will have the value of relationship_id. If it's null or false, we know it doesn't exist, so we want to execute another query to insert the posted data.
OK, this should be extremely simple. In fact, I've done this before. Its just lost somewhere in a deep pocket of my mind.
This is what I'm trying to do. I have a form that submits values to a processing php file. wonderful... no problem there. But, I want the processing file to first check to see if an entry with those exact values has already been entered, and if not, continue with the insert command.
This is what I know,
The variables are passed to the php file though post,
php file grabs the post variables and creates normal variables out of them
a select command is run like this:
How do I execute an insert (or anything) on a failed select?
The only thing I could think of was to use an if statement checking for a false value for the relationship_id
Help a brotha' out!
Thanks Guys!
-Jake
YouTube.com/karpadiem