更新MYSQL数据库失败,为什么?

时间:2010-12-05 11:31:42

标签: php mysql

$serverid = mysql_query("SELECT * FROM serveripank");
while($row = mysql_fetch_array($serverid)) {
  require_once('../getdata/cs-getdata.php');
  $result = $cstrike->getData();
  $SNAME = $result['cstrike']['ServerVars']['servername']; //Server name
  $SMAP = $result['cstrike']['ServerVars']['mapname']; //Map name
  $SCP = $result['cstrike']['ServerVars']['currentplayers']; //Server Current Players
  $SMP = $result['cstrike']['ServerVars']['maxplayers']; //Server Max Players
  // Servers name MAX 25 letters & Map
  $SNAME = substr($SNAME, 0, 25);
  $SMAP = substr($SMAP, 0, 20);

  $id = $row['id'];
  mysql_query("UPDATE serveripank SET players = '$SCP' WHERE id = '$id'");
  mysql_query("UPDATE serveripank SET maxplayers = '$SMP' WHERE id = '$id'");
  mysql_query("UPDATE serveripank SET map = '$SMAP' WHERE id = '$id'");
  mysql_query("UPDATE serveripank SET srname = '$SNAME' WHERE id = '$id'");
}

我在require_once('../getdata/cs-getdata.php');

中使用此脚本http://dev.ush-network.de/2010/02/02/gathering-counter-strike-data-using-php-sockets/comment-page-1/#comment-22

当我转到更新我的MYSQL数据库的链接时,它不显示任何错误,但在数据库中行是空的。

这是在我的cs-getdata.php文件@底部,所以它可以用正确的值更新所有服务器......(不知道如何更好地解释)

list($ip, $port) = explode(":", "row['ip']"); $cstrike = new cstrike_statistics(); $cstrike->setHostname('$ip'); $cstrike->setPort($port);

我的问题是它没有获取服务器信息/并且它将空值放入数据库。

1 个答案:

答案 0 :(得分:-1)

天啊,为什么没有人注意到我的愚蠢错误?

list($ip, $port) = explode(":", "row['ip']"); 
$cstrike = new cstrike_statistics(); 
$cstrike->setHostname('$ip'); 
$cstrike->setPort($port);

应该是

list($ip, $port) = explode(":", "$row['ip']"); 
$cstrike = new cstrike_statistics(); 
$cstrike->setHostname('$ip'); 
$cstrike->setPort($port);

错误是:$row['ip']