lpxxfaintxx Posted April 1, 2006 Share Posted April 1, 2006 [code]<?phprequire_once "maincore.php";require_once "subheader.php";require_once "side_left.php";opentable('Add Category');$owner = $userdata['user_name'];$categoryname = addslashes(strip_tags($_POST['catname']));$description = addslashes(strip_tags($_POST['description']));$status = $_POST['status'];$date = date('F d, Y'); $idq = mysql_query("SELECT `id` FROM `registered_cat` ORDER BY `id` DESC LIMIT 1"); $ida = mysql_fetch_assoc($idq); $id = $ida['id'] + 1; $sql2 = mysql_query("SELECT '$categoryname' FROM registered_cat WHERE owner='$username'");$result2 = mysql_num_rows($sql2); if($result2=="0"){echo "Category Exists Already!!<br/>";exit;} else {MYSQL_QUERY("INSERT INTO registered_cat (`owner`,`cat_name`,`cat_description`,`status`,`date`,`id`) VALUES ('$owner','$categoryname','$description','$status','$date','$id')"); echo "Category Added! <a href='viewpage.php?page_id=7'>Click here to go back.</a>";}require_once "footer.php";?>[/code]Even though a row does not exist, it says it is. What am I doing wrong here? Help would be greatly appreciated!Regards, AIMMultimedia.com Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 1, 2006 Share Posted April 1, 2006 You're "if" condition is wrong. You have:[code]<?phpif($result2=="0"){echo "Category Exists Already!!<br/>";exit;?>[/code]it should be:[code]<?phpif($result2 > 0){echo "Category Exists Already!!<br/>";exit; ?>[/code]Ken Quote Link to comment Share on other sites More sharing options...
lpxxfaintxx Posted April 1, 2006 Author Share Posted April 1, 2006 I did what you said but it gives me the same error. [code]<?phprequire_once "maincore.php";require_once "subheader.php";require_once "side_left.php";opentable('Add Category');$owner = $userdata['user_name'];$categoryname = addslashes(strip_tags($_POST['catname']));$description = addslashes(strip_tags($_POST['description']));$status = $_POST['status'];$date = date('F d, Y'); $idq = mysql_query("SELECT `id` FROM `registered_cat` ORDER BY `id` DESC LIMIT 1"); $ida = mysql_fetch_assoc($idq); $id = $ida['id'] + 1; $sql2 = mysql_query("SELECT '$categoryname' FROM registered_cat WHERE owner='$owner'");$result2 = mysql_num_rows($sql2); if($result2 > 0){ opentable('Category Exists!'); echo "Category Exists Already!! <a href='viewpage.php?page_id=7'>Click here to go back.</a><br/>";} else { opentable('Category Added!'); MYSQL_QUERY("INSERT INTO registered_cat (`owner`,`cat_name`,`cat_description`,`status`,`date`,`id`) VALUES ('$owner','$categoryname','$description','$status','$date','$id')"); echo "Category Added! <a href='viewpage.php?page_id=7'>Click here to go back.</a>";}require_once "footer.php";?>[/code]Could it be the mysql query? Quote Link to comment Share on other sites More sharing options...
toplay Posted April 1, 2006 Share Posted April 1, 2006 Use backtick marks and not single quotes on the query. You then must check for errors before executing any subsequent MySQL commands. Example[code]$sql2 = mysql_query("SELECT `$categoryname` FROM registered_cat WHERE `owner` = '$owner'") or die('Error: ' . mysql_error());$result2 = mysql_num_rows($sql2);...[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.