简体   繁体   中英

What's the solution to this error?

if($placed != true){    
  $_SESSION["eventid"][]   = "$r[id]";
  $_SESSION["selection"][] = "$selection";
  $_SESSION["title"][] = "$r[hometeam] - $r[awayteam]";

And the error is:

Warning: Cannot use a scalar value as an array in /home2/**/bet/add_bet.php on line 54
Fatal error: [] operator not supported for strings in /home2/**/bet/add_bet.php on line 55

I know it has to do with an array; but which would be the solution here??? Im confused!

It's not like i can type $_SESSION["eventid"][] = array();

FULL CODE CAN BE SEEN HERE

If you var_dump your session variables, you will see that you have defined $_SESSION['eventid'] et al. as strings somewhere in your code. As such, treating them as arrays will fail.

You will need to initialise your session variables to arrays explicitly.

You shouldnt use double quotes, also you need youse single quotes in $r , also use concatenation with single quotes:

     $_SESSION["eventid"][]   = $r['id'];
     $_SESSION["selection"][] = $selection;
     $_SESSION["title"][] = $r['hometeam'] .' - ' . $r['awayteam'];

I think you want something like this:

    $_SESSION["eventid"] = $r['id'];
    $_SESSION["selection"] = $selection;
    $_SESSION["title"] = $r['hometeam'] .' - ' . $r['awayteam'];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM