How can we combine a single and a pair?
$ New ['name'] = strval ($ _ POST ['name']); $ tags = strval ($ _ POST ['tag']); $ new ['status'] = intval ($ _ POST ['status']); $ new ['displayorder'] = intval ($ _ POST ['order']); if (! $ New ['status'] = 1 |! $ New ['status'] = 2) {self: output (['title' => 'invalid parameter ', 'type' => 'error']);} $ mid = intval ($ _ POST ['mid ']); if (strstr ($ tags,', ') {$ tagstr = []; $ pdo_r = Bridge :: pdo (Bridge: DB_TAG_R); $ tagsDB = explode (',', $ tags); foreach ($ tagsDB as $ k => $ v) {$ v = trim ($ v); $ query = $ pdo_r-> prepare ("SELECT TagNameId FROM 'tagname' WHERE TagName =: channelName "); $ query-> execute ([': channelname' => $ v]); $ rs = $ query-> fetch (); if (! $ Rs) {$ error_msgs = 'This ''. $ v. '",'. 'tag does not exist'; self: output (['title' => "$ error_msgs", 'type' => 'error']);} $ tagstr [] = $ rs ['tagnameid'] ;}} else {$ v = trim ($ tags); $ pdo_r = Bridge: pdo (Bridge: DB_TAG_R ); $ query = $ pdo_r-> prepare ("SELECT TagNameId FROM 'tagname' WHERE TagName =: channelName"); $ query-> execute ([': channelname' => $ v]); $ rs = $ query-> fetch (); if (! $ Rs) {$ error_msgs = 'This ''. $ v. '",'. 'tag does not exist'; self: output (['title' => "$ error_msgs", 'type' => 'error']);} $ tagstr [] = array_unique ($ rs ['tagnameid']);} $ new ['tags'] = serialize ($ tagstr); $ pdo_w = Bridge :: pdo (Bridge: DB_HEALTH_W); $ re = $ pdo_w-> update ('articlechannel', $ new, ['channelid' => $ mid]); $ this-> adminLog ('tagmodifie', $ mid, 'update', serialize ($ new); if ($ re> 0) {self :: output (['title' => 'Operation succeeded ', 'type' => 'success']);} self :: output (['title' => 'Operation failed', 'type' => 'error']);}
Reply to discussion (solution)
Remove the else branches of if (strstr ($ tags, ',') and if (strstr ($ tags, ',')
That is, only the true branch of if (strstr ($ tags, ',') is retained.