Notifications
Clear all

Array Problem...

3 Posts
3 Users
0 Reactions
2,503 Views
(@tammster)
Posts: 3
New Member
Topic starter
 

Hello All,

So when I "Add New Story" while adding a chapter I get this message...
Array to string conversion in /home2/****/public_html/fanfiction/includes/storyform.php on line 77

Here is what is on lines 76-78 of this page:}
$output .= "</select></label>
<input type='hidden' name='coauthors' id='coauthors' value='$couids'></div>";
}

Could someone be so kind as to tell me what is wrong with this code and how to fix it?

πŸ™‚


 
Posted : 23/09/2015 3:26 am
(@alvina)
Posts: 3
New Member
 

Hello Tammster,

If I check the current storyform.php I see the following code:


$couids = array() ;
if(is_array($stories['coauthors']) && count($stories['coauthors'])) {
$coauths = dbquery("SELECT "._PENNAMEFIELD." as penname, "._UIDFIELD." as uid FROM "._AUTHORTABLE." WHERE FIND_IN_SET("._UIDFIELD.", '".implode(",", $stories['coauthors'])."') > 0");
while($c = dbassoc($coauths)) {
if($c['uid'] == $stories['uid']) continue;
$output .= "<option label='".$c['penname']."' value='".$c['uid']."'>".$c['penname']."</option>";
$couids[] = $c['uid'];
}
$couids = implode(",", $couids);
}
$output .= "</select></label>
<input type='hidden' name='coauthors' id='coauthors' value='$couids'></div>";
}

Your error simple means that $couids is an array (a list) while it should be a string (simple text).
Try moving line 74 to line 75, like this:

$couids = array() ;
if(is_array($stories['coauthors']) && count($stories['coauthors'])) {
$coauths = dbquery("SELECT "._PENNAMEFIELD." as penname, "._UIDFIELD." as uid FROM "._AUTHORTABLE." WHERE FIND_IN_SET("._UIDFIELD.", '".implode(",", $stories['coauthors'])."') > 0");
while($c = dbassoc($coauths)) {
if($c['uid'] == $stories['uid']) continue;
$output .= "<option label='".$c['penname']."' value='".$c['uid']."'>".$c['penname']."</option>";
$couids[] = $c['uid'];
}
}
$couids = implode(",", $couids);
$output .= "</select></label>
<input type='hidden' name='coauthors' id='coauthors' value='$couids'></div>";
}

Could you let me know if this works? If you still get an error you can try this:

$couids = '' ;
if(is_array($stories['coauthors']) && count($stories['coauthors'])) {
$couids = array() ;
$coauths = dbquery("SELECT "._PENNAMEFIELD." as penname, "._UIDFIELD." as uid FROM "._AUTHORTABLE." WHERE FIND_IN_SET("._UIDFIELD.", '".implode(",", $stories['coauthors'])."') > 0");
while($c = dbassoc($coauths)) {
if($c['uid'] == $stories['uid']) continue;
$output .= "<option label='".$c['penname']."' value='".$c['uid']."'>".$c['penname']."</option>";
$couids[] = $c['uid'];
}
$couids = implode(",", $couids);
}
$output .= "</select></label>
<input type='hidden' name='coauthors' id='coauthors' value='$couids'></div>";
}

 
Posted : 25/09/2015 7:30 am
(@killa)
Posts: 14
Active Member
 

Very belated, but I just wanted to say that I tried this solution and it appears to have worked. Thank you!


 
Posted : 20/06/2016 1:30 pm
Share: