【问题标题】:syntax error, unexpected ':'语法错误,意外的“:”
【发布时间】:2015-04-28 07:54:53
【问题描述】:

我有下面的代码,当我加载它时,我总是得到这个错误..

function newPlayer($wallet) {
  generate_: {
    $hash=generateHash(32);
    }
  if (mysql_num_rows(mysql_query("SELECT `id` FROM `players` WHERE `hash`='$hash' LIMIT 1"))!=0) goto generate_;
      $alias='Player_';
      $alias_i=mysql_fetch_array(mysql_query("SELECT `autoalias_increment` AS `data` FROM `system` LIMIT 1"));
      $alias_i=$alias_i['data'];
      mysql_query("UPDATE `system` SET `autoalias_increment`=`autoalias_increment`+1 LIMIT 1");
      mysql_query("INSERT INTO `players` (`hash`,`alias`,`time_last_active`,`server_seed`) VALUES ('$hash','".$alias.$alias_i."',NOW(),'".generateServerSeed()."')");
      header('Location: ./?unique='.$hash.'# Do Not Share This URL!');
      exit();
}

错误:

Parse error: syntax error, unexpected ':' in /home/a1180044/public_html/inc/functions.php on line 49

第 49 行是生成_:

【问题讨论】:

  • PHP 不是 javascript
  • generate_:的作用是什么?
  • 你是否在使用古老的 PHP 版本?

标签: php mysql function


【解决方案1】:

尽量不要使用 goto。

通过使用 goto,您将迷失在自己的代码中,因为您必须在每次 goto 指向的地方进行搜索。

在这里你可以通过写作来做你想做的事情:

if (mysql_num_rows(mysql_query("SELECT `id` FROM `players` WHERE `hash`='$hash' LIMIT 1"))!=0) {
    $hash=generateHash(32);
}

【讨论】:

  • 天哪,goto 语句是在 OP 中可怕的缩进代码块中滚动之后出现的。 @OP 是的,不要。
  • 谢谢。我更换了所有的goto,现在很好。谢谢:)
猜你喜欢
  • 2018-08-03
  • 1970-01-01
  • 2011-10-28
  • 1970-01-01
  • 1970-01-01
  • 2017-09-12
  • 2011-10-16
  • 2013-10-12
  • 2011-07-21
相关资源
最近更新 更多