我现在正在处理的这段代码有一个非常奇怪的问题。它是游戏的地图编辑器,它将每个磁贴的变量发送到另一个PHP文件以更新mySQL数据库。
到目前为止,地图编辑器代码显示地图并加载所有内容。如果直接在代码中给出变量,则映射更新(mupdate)PHP文件会正确更新数据库。
但是,当我在文件之间将数据作为POST变量发送时,mupdate文件会在前18次左右完美地接收它们,然后再无法读取。
有人能说清楚为什么会这样吗?
(为我的邋sc编码提前道歉,对于地图编辑器的荒谬加载时间它正在加载整个地图,我可能会在某个时候将其更改为10x10部分,但POST var问题仍然适用。 )
地图编辑器:
http://www.locktopia.netne.net/mapedit.php
<?php
//Database Connection
include('DBconnect.php');
//Map Defaults
$world="slums";
$mapInfo=mysql_fetch_assoc(
mysql_query("SELECT * FROM `mapindex` WHERE `NAME` = '".$world."'")
);
$tileSet= $mapInfo['TILESET'];
//Loads Current Location
// Splits the Database Location into the co-ordinates.
$startX=$startY = 1;
list($maxX, $maxY) = split('[,]', $mapInfo['SIZE']);
//Listing tiles in directory
$tileDir = "images/tileSets/".$tileSet."/";
$tilecount = count(glob("" . $tileDir . "*.png"));
$objDir = "images/tileSets/objects/";
$Objcount = count(glob("" . $objDir . "*.png"))-1;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Map Editor</title>
</head>
<body>
//MAP EDITOR V2
<form action="mupdate.php" method="post">
<?php
//Map and Co-Ord values
echo('<input name="world" type="hidden" id="world" value="'.$mapInfo['NAME'].'" />');
echo('<input name="size" type="hidden" id="size" value="'.$mapInfo['SIZE'].'" />');
?>
<table width="100%" border="1" cellpadding="0" cellspacing="0">
<?php
echo($mapInfo['NAME']);
echo($mapInfo['SIZE']);
while($startY<=$maxY){
echo("<tr>"); //BEGIN ROW
while($startX<=$maxX){
echo("<td>");//BEGIN CELL
///////////////////////CELL CONTENT///////////////////////
//Tile Menu
echo('Tile:<br /><select name="'.$startX.','.$startY.'-tile" id="'.$startX.','.$startY.'-tile" size="1" style="overflow:scroll;width:40px;height:20px;">');
$possibleTile=1;
while($possibleTile<=$tilecount){
echo('<option value="'.$possibleTile.'" style="width:40px; height:40px; background-image: url('.$tileDir.$possibleTile.'.png);">'.$possibleTile.'</option>');
$possibleTile++;
}
echo('</select><br />');
echo('Obj LVL1:<br /><select name="'.$startX.','.$startY.'-ob1" id="'.$startX.','.$startY.'-ob1" size="1" style="overflow:scroll;width:40px;height:20px;">');
$possibleObject=0;
while($possibleObject<=$Objcount){
echo('<option value="'.$possibleObject.'" style="width:40px; height:40px; background-image: url('.$objDir.$possibleObject.'.png);">'.$possibleObject.'</option>');
$possibleObject++;
}
echo('</select><br />');
echo('Obj LVL2:<br /><select name="'.$startX.','.$startY.'-ob2" id="'.$startX.','.$startY.'-ob2" size="1" style="overflow:scroll;width:40px; height:20px;">');
$possibleObject=0;
while($possibleObject<=$Objcount){
echo('<option value="'.$possibleObject.'" style="width:40px; height:40px; background-image: url('.$objDir.$possibleObject.'.png);">'.$possibleObject.'</option>');
$possibleObject++;
}
echo('</select>');
echo('Buildable:<br /><select name="'.$startX.','.$startY.'-build" id="'.$startX.','.$startY.'-build" size="1" style="overflow:scroll;width:40px; height:20px;">');
$possibleOption=0;
while($possibleOption<=1){
echo('<option value="'.$possibleOption.'">'.$possibleOption.'</option>');
$possibleOption++;
}
echo('</select>');
echo('Type:<br /><select name="'.$startX.','.$startY.'-type" id="'.$startX.','.$startY.'-type" size="1" style="overflow:scroll;width:40px; height:20px;">');
echo('<option value="passable">Walkable</option>');
echo('<option value="impassable">Blocked</option>');
echo('<option value="teleport">Teleport</option>');
echo('</select>');
//////////////////////////////////////////////////////////
echo("</td>");//END CELL
$startX++;
}
echo("</tr>");//END ROW
$startY++;
$startX=1;
}
?>
</table>
<input type="submit" name="submit" />
</form>
</body>
</html>
地图更新程序:[点击上面的“提交”会转到您的身边)
<?php
//Database Connection
include('common/connectDB.php');
//Printing the Data in the POST array
print_r($_POST);
// A Spacer for convenience's sake
echo('<br /><hr> <br />');
//Setting the Name of the map to update
$mapName=$_POST['world'];
//Getting the Max X/Y dimensions of the map (in tiles)
list($mapX, $mapY) = split('[,]', $_POST['size']);
//Setting the start points for the loops
$currX=1;
$currY=1;
//Row (Y-Axis) Update Loop
while($currY<=$mapY){
//Column (X-Axis) Update Loop
while($currX<=$mapX){
//Checking for missing data on cell Type (Walkable/Blocking/Teleport)
if(empty($_POST[$currX.','.$currY.'-type'])) {
die("Failed on 'type': currX={$currX} - currY={$currY} - POST DATA: {$_POST[$currX.','.$currY.'-type']}");
}
//Checking for missing data on cell Tile (The base graphic, represented by a number which matches an image file)
if(empty($_POST[$currX.','.$currY.'-tile'])) {
die("Failed on 'tile': currX={$currX} - currY={$currY} - POST DATA: {$_POST[$currX.','.$currY.'-tile']}");
}
//mysql_query
echo("UPDATE `maps` SET `TYPE`='".$_POST[$currX.','.$currY.'-type']."', `TILE` = '".$_POST[$currX.','.$currY.'-tile']."', `BUILD` = '".$_POST[$currX.','.$currY.'-build']."', `OBJECTS` = '".$_POST[$currX.','.$currY.'-ob1'].",".$_POST[$currX.','.$currY.'-ob2']."' WHERE CONVERT( `maps`.`MAP` USING utf8 ) = '".$mapName."' AND CONVERT( `maps`.`XY` USING utf8 ) = '".$currX.",".$currY."'");
//A spacer for Clarity's sake
echo('<br />');
//Updating the Column (X-Axis) Value
$currX++;
}
echo("Row ".$currY." of ".$mapY." completed.<br>Sleeping 1 Second.");
//Resetting Column (X-Axis) to 1
$currX=1;
//Updating the Column (Y-Axis) Value
$currY++;
//A spacer for Clarity's sake
echo('<br />');
//Sleep for 1 Second. Stops the DB being overloaded with requests (as discovered with my map generator)
//sleep(1); //uncommented in working version
}
//Closing the DB connection
mysql_close();
?>
只是为了澄清: 在第19条之后,代码的输出未能包括Tile,Type和Build的值:
比较
没有。 19 -
UPDATE `maps` SET `TYPE`='passable', `TILE` = '1', `BUILD` = '0', `OBJECTS` = '0,0' WHERE CONVERT( `maps`.`MAP` USING utf8 ) = 'slums' AND CONVERT( `maps`.`XY` USING utf8 ) = '19,1'
没有。 20 -
UPDATE `maps` SET `TYPE`='', `TILE` = '1', `BUILD` = '', `OBJECTS` = '0,0' WHERE CONVERT( `maps`.`MAP` USING utf8 ) = 'slums' AND CONVERT( `maps`.`XY` USING utf8 ) = '20,1'
没有。 21 -
UPDATE `maps` SET `TYPE`='', `TILE` = '', `BUILD` = '', `OBJECTS` = ',' WHERE CONVERT( `maps`.`MAP` USING utf8 ) = 'slums' AND CONVERT( `maps`.`XY` USING utf8 ) = '21,1'
附录:感谢Phil指出mysql_close()错误,我添加了你建议的代码,并添加了另一个var的检查(我不能用它来检查构建,因为它使用了一个int是真还是假)。 有趣的是,有一次是printr($ _ POST);给了我完整的数据量,但其余的代码在20号时失败了,现在它只显示数字20。 我想知道如果我在数组中使用post值(例如$ _POST [20,1] [type])是否有帮助
答案 0 :(得分:1)
可能会看到的事情:
脚本超时
POST大小。有限制,请参阅php.ini
答案 1 :(得分:0)
我要做的第一件事就是调试
在print_r($_POST)
之前 $mapName=$_POST['world'];
然后,我会在你的第二个循环中添加以下内容:
if(empty($_POST[$currX.','.$currY.'-type']))
die("Failed: currX={$currX} - currY={$currY} - POST DATA: {$_POST[$currX.','.$currY.'-type']}");
另外,mysql_close带圆括号()=&gt; mysql_close();
我希望有帮助