Browse code

user/favau.php: fix bug with adding an already-favorited author as favorites handling bringing up PHP warnings and bugging out the entire thing

Clarissa Walker authored on 2026/11/03 19:05:25
Showing 1 changed files
... ...
@@ -36,8 +36,8 @@ if(empty($favorites)) accessDenied( );
36 36
 	$edit = isset($_GET['edit']) && isNumber($_GET['edit']) ? $_GET['edit'] : false;
37 37
 	$author = explode(",", $add);
38 38
 	$author = array_filter($author, "isNumber");
39
-	$array_pennames = array();
40 39
 	$pennames = '';
40
+	$pennameslist = array();
41 41
 	if(($add || $edit || $delete) && !isMEMBER) accessDenied( );
42 42
 
43 43
 	if(isMEMBER && $uid == USERUID) {
... ...
@@ -61,7 +61,7 @@ if(empty($favorites)) accessDenied( );
61 61
 		}
62 62
 		if(($add || $edit) && !isset($_POST['submit'])) {
63 63
 			if($add) {
64
-				$check = dbquery("SELECT item FROM ".TABLEPREFIX."fanfiction_favorites WHERE uid = '".USERUID."' AND ".findclause("item", $author)." AND type = 'AU'");
64
+				$check = dbquery("SELECT item FROM ".TABLEPREFIX."fanfiction_favorites WHERE uid = '".USERUID."' AND FIND_IN_SET('item', '".(is_array($author) ? implode(",", $author) : $author)."') > 0 AND type = 'AU'");
65 65
 				if(dbnumrows($check)) {
66 66
 					while($c = dbassoc($check)) {
67 67
 						$edit[] = $c['item'];
... ...
@@ -71,9 +71,9 @@ if(empty($favorites)) accessDenied( );
71 71
 				else {
72 72
 					$pQuery = dbquery("SELECT "._PENNAMEFIELD." as penname FROM "._AUTHORTABLE." WHERE ".findclause(_UIDFIELD, $author));
73 73
 					while($pRes = dbassoc($pQuery)) {
74
-						$array_pennames[] = $pRes['penname'];
74
+						$pennameslist[] = $pRes['penname'];
75 75
 					}
76
-					$pennames = implode(", ", $array_pennames);
76
+					$pennames = implode(", ", $pennameslist);
77 77
 				}
78 78
 				$output = "<div class='sectionheader'>"._ADDTOFAVORITES.": ".$pennames."</div>";
79 79
 			}
... ...
@@ -88,9 +88,9 @@ if(empty($favorites)) accessDenied( );
88 88
 					$author = array($edit);
89 89
 					$pQuery = dbquery("SELECT "._PENNAMEFIELD." as penname FROM "._AUTHORTABLE." WHERE ".findclause(_UIDFIELD, $author));
90 90
 					while($pRes = dbassoc($pQuery)) {
91
-						$array_pennames[] = $pRes['penname'];
91
+						$pennameslist[] = $pRes['penname'];
92 92
 					}
93
-					$pennames = implode(", ", $array_pennames);
93
+					$pennames = implode(", ", $pennameslist);
94 94
 					$output .= "<div class='sectionheader'>"._ADDTOFAVORITES.": ".$pennames."</div>";
95 95
 				}
96 96
 			}