cturner Posted January 6, 2007 Share Posted January 6, 2007 The code that is below is suppose to add a category name (categoryname) as well as a short name (category) for the category and it only adds the short name for the category. I have tested my code to view the categories but the short name only displays. Can someone please have a look at my code and tell me how I can solve this problem? Thanks in advance.[code=php:0]require "config.php";$category = mysql_real_escape_string($_POST['category']);$categoryname = mysql_real_escape_string($_POST['categoryname']);$arrErrors = array();if (isset($_POST['addbtn'])) { if ($category = '') { $arrErrors['category'] = 'Please enter a short name for the category.'; } if ($categoryname = '') { $arrErrors['categoryname'] = 'Please enter a description for the category.'; } $sql = mysql_query("SELECT `categoryname` FROM `tbl_categories` WHERE 'categoryname' = '$categoryname'") or die ("Could not query because: ".mysql_error()); $check = mysql_num_rows($sql); if ($check != 0) { $arrErrors['categoryname'] = 'The category already exists.'; } if (count($arrErrors) == 0) { $result = "INSERT INTO `tbl_categories` (`category`, `categoryname`) VALUES ('$category', '$categoryname')"; if (mysql_query($result)) { header ('Location: category_added.php'); } else { print "<p>Could not add the entry because: <b>" . mysql_error() . "</b>. The query was $result.</p>"; } } else { // The error array had something in it. There was an error. // Start adding error text to an error string. $strError = '<div class="formerror"><p>Please check the following and try again:</p><ul>'; // Get each error and add it to the error string // as a list item. foreach ($arrErrors as $error) { $strError .= "<li>$error</li>"; } $strError .= '</ul></div>'; }}mysql_close();[/code] Quote Link to comment Share on other sites More sharing options...
fenway Posted January 6, 2007 Share Posted January 6, 2007 So what's the problem? With which query? Quote Link to comment Share on other sites More sharing options...
cturner Posted January 6, 2007 Author Share Posted January 6, 2007 The problem is the INSERT INTO only adds category to the database and not the categoryname. Quote Link to comment Share on other sites More sharing options...
fenway Posted January 7, 2007 Share Posted January 7, 2007 And you're sure that the original POST variable is not a blank string? Quote Link to comment Share on other sites More sharing options...
cturner Posted January 7, 2007 Author Share Posted January 7, 2007 Yes I am sure that the original POST variable isn't a blank string. Quote Link to comment Share on other sites More sharing options...
fenway Posted January 7, 2007 Share Posted January 7, 2007 Well, the insert statement isn't failing, so I have to disagree with you. 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.