Fixed category saving, added unique key, removed deprecated templates:
[mailer.git] / inc / modules / member / what-categories.php
index 2812f0b0707d822f8e36fbb04497b88004290710..13075a351e7460a95849f4b0e5960920c7176cfa 100644 (file)
@@ -82,8 +82,11 @@ if (!SQL_HASZERONUMS($result)) {
                                        $result_user = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_user_cats` WHERE `userid`=%s AND `cat_id`=%s LIMIT 1",
                                                array(getMemberId(), bigintval($cat)), __FILE__, __LINE__);
 
-                                       if (!SQL_HASZERONUMS($result_user)) {
-                                               $sql = "INSERT INTO `{?_MYSQL_PREFIX?}_user_cats` (userid, cat_id) VALUES ('%s','%s')";
+                                       // Debug message
+                                       //* DEBUG: */ logDebugMessage(__FILE__, __LINE__, 'cat='.$cat.',joined='.$joined.',getMemberId()='.getMemberId().',SQL_HASZERONUMS()='.intval(SQL_HASZERONUMS($result_user)));
+
+                                       if (SQL_HASZERONUMS($result_user)) {
+                                               $sql = "INSERT INTO `{?_MYSQL_PREFIX?}_user_cats` (`userid`, `cat_id`) VALUES (%s,%s)";
                                        } // END - if
 
                                        // Free memory
@@ -133,7 +136,7 @@ if (!SQL_HASZERONUMS($result)) {
                        $content['jy'] = '';
 
                        // When we found an entry don't read it, just change the jx elements
-                       if (isPostRequestParameterSet('cat')) {
+                       if ((isFormSent()) && (isPostRequestParameterSet('cat'))) {
                                // Form sent?
                                if (postRequestParameter('cat', $content['id']) =='Y') {
                                        $content['jy'] = ' checked="checked"';
@@ -144,7 +147,7 @@ if (!SQL_HASZERONUMS($result)) {
                                if (countSumTotalData(getMemberId(), 'user_cats', 'id', 'userid', true, sprintf(" AND `cat_id`=%s", bigintval($content['id']))) == 1) {
                                        $content['jn'] = '';
                                        $content['jy'] = ' checked="checked"';
-                               }
+                               } // END - if
                        }
 
                        // Load row template and switch colors