POST değişkeni sorunu

2 Cevap php

Ben bu kod ben şu anda üzerinde çalışıyorum ile gerçekten garip bir sorun yaşıyorum. Bu mySQL veritabanını güncellemek için başka bir PHP dosyası her karo için değişkenleri gönderir bir oyun için bir harita editörü var.

Şimdiye kadar harita editörü kod haritasını görüntüler ve her şey yolunda yükler. Doğrudan kodda değişkenleri verilirse harita güncelleme (mupdate) PHP dosyası doğru, veritabanını günceller.

Ben dosyaları arasında bir POST değişkeni olarak veri göndermek Ancak, mupdate dosya daha sonra bir daha okumak için başarısız, ilk 18 kez ya da öylesine için mükemmel onları alır.

Herkes neden bu oluyor biraz ışık tutabilir?

(Apologies in advance for my scruffy coding and for the ridiculous load time of the map editor it is loading an entire map, I may change that to 10x10 sections at some point, but the POST var problem still applies.)

Harita editörü:

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>

Harita Updater: [yukarıdaki sayfada Gönder tıklamak ona götürecek)

 <?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();
?>

Just to Clarify: The Output of the Code fails to include the Values for Tile, Type and Build after the 19th entry:

Karşılaştırın:

No: 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'

No: 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'

No: 21 -

UPDATE `maps` SET `TYPE`='', `TILE` = '', `BUILD` = '', `OBJECTS` = ',' WHERE CONVERT( `maps`.`MAP` USING utf8 ) = 'slums' AND CONVERT( `maps`.`XY` USING utf8 ) = '21,1'

Appendix: Thanks Phil for pointing out the mysql_close() mistake, I've added the code you suggested and also added a check for another var (I can't use it to check for build though as it uses a single int as true or false). Interestingly enough, one time the printr($_POST); gave me the complete amount of data, but the rest of the code failed at number 20, now it only displays it up to number 20. I'm wondering if it would help if I made the post values in arrays (i.e. $_POST[20,1][type])

2 Cevap

Potansiyel bakmak şeyler:

  1. Komut Mola

  2. POST boyutu. Sınırları php.ini içinde post_max_size görmek vardır

Ben sorunun noktasını pin için denemek için yapacağı ilk şey aramak için

print_r($_POST) önce $mapName=$_POST['world'];

Sonra, senin 2. döngüde aşağıdaki eklersiniz:

if(empty($_POST[$currX.','.$currY.'-type'])) 
     die("Failed: currX={$currX} - currY={$currY} - POST DATA: {$_POST[$currX.','.$currY.'-type']}");

Ayrıca, mysql_close parantez alır () => mysql_close();

Umarım yardımı olur