Hi,
I am trying to check MYSQL table field for existing Tags. If they exist i dont want it to insert the tag.
If they dont exist i want it to run the INSERT query.
My code below wont work though.. it just keeps returning already exists even when the tag dosent exist in the table.
Can anyone plese tell me what i am doing wrong and maybe help with an example.
Thanks in advance :-)
//make variables safe
$tagname = mysql_real_escape_string($_POST['tag']);
$status = 0;
$new = 1;
//get existing tagnames first
$sql1 = "SELECT tag_name FROM Tags";
$result1 = mysql_query($sql1);
while($tagrow = mysql_fetch_array($result1))
{
$existingTags = $tagrow['tag_name'];
}
if( $existingTags = $tagname ) {
echo "tag allready exists!";
} else {
//insert new tag
$sql = "
INSERT INTO Tags
SET
tag_name = '$tagname'";
$result = mysql_query($sql);
}