简体   繁体   English

该错误的解决方案是什么?

[英]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(); 好像我不能输入$_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. 如果使用var_dump会话变量,则会看到已定义$_SESSION['eventid']等。 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: 您不应该使用双引号,也需要在$r使用单引号,还应使用带单引号的串联:

     $_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'];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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