Hi all, I have the follwing code which doesn't work:

PHP Code:
function add_p_category($category) {
    
        
$qLinkExists "SELECT * FROM al_p_category WHERE category='$category'";
        
$qInsertLink "INSERT INTO al_p_category(category) 
                                        VALUES ('
$category')";
                                                 
        if (
mysql_num_rows($qLinkExists) > 0) {
            return 
"Already exists";
        }
        else {
            
$result mysql_query($qInsertLink); 
            return 
"Category added";
        }
    } 
// End: function addcategory 
It inserts into the database fine, but when I already have an entry already in the database, "if (mysql_num_rows($qLinkExists) > 0) {" should pick it up, but it just inserts it anyway. Is there anything wrong with the above code? I couldn't see anything wrong, but someone else maybe able to.

The other side of the code is this:

PHP Code:
<?php 
if (isset($_POST['submittype'])) {
        
$submittype $_POST['submittype'];
        
$id $_POST['id'];
        
$category $_POST['category'];
        
$deleteid $_POST['deleteid'];
        
$groupname $_POST['groupname'];

$groupupdate = new permissions();
            if (
$submittype == "new") {
                
$perm="add_permissions";
                require(
"../user_control/checkperm.php");
                
$id $groupupdate->add_permission($groupname$category);
            }
            if (
$submittype == "edit") {
                
$perm="edit_permissions";
                require(
"../user_control/checkperm.php");
                
$message $groupupdate->modify_permission($id$category);
            }
            if (
$submittype == "delete") {
                
$perm="delete_permissions";
                require(
"../user_control/checkperm.php");
                
$message $groupupdate->delete_permission($deleteid);
            }
            if (
$submittype == "newc") {
                
$perm="add_perm_category";
                require(
"../user_control/checkperm.php");
                
$message $groupupdate->add_p_category($category);
            }
            if (
$submittype == "delc") {
                
$perm="delete_perm_category";
                require(
"../user_control/checkperm.php");
                
$message $groupupdate->delete_p_category($deleteid);
            }
    }
?>
 <div id="newc">
  <div align="center">
    <p>&nbsp;</p>
    <p>Category name:</p>
  </div>
  
    <div align="center">
        <form name="addcategory" method="Post" action="main.php?p=showpermission">
        <input type="text" name="category">
    </div>
    <div align="center">
        <input type="hidden" name="submittype" value="newc">
      <input type="Submit" value="Submit">
      <input type="button" value="Cancel" onclick="MM_showHideLayers('newc','','hide')">
            </form>
    </div>
</div>
Any help appreciated.

David