可变转移失败

Well, I have a hidden form on one page just to send a value to another php file. The first file is:

<?php

    $ncarts = $_POST["ncarts"];
    $npedras = $_POST["npedras"];

echo "<html><head><title>Insirss</title></head><body><form method=\"post\" action=\"puxar.php\">";

$abrindo = fopen ("cartelas.txt", "a+");

for ($c=1; $c<=$ncarts; $c++){
         for ($n=1; $n<=$npedras; $n++){
           $x = "termo{$n}da{$c}";
           $dados = $_POST[$x]."
";
           fwrite ($abrindo, $dados);
         }
}
fclose ($abrindo);
$zeta = $c-1;

if ($zeta==1) {
echo "Voce teve uma registrada com sucesso <br><hr>";
} elseif ($zeta > 1) {
echo "Voce teve " . $zeta . " registradas!<br><hr>";
} else {
echo "Voce nao registrou nada! <br><hr>
<a href=\"http:/site\"> Ir para o inicio </a> <br> ";
}

echo "<a href=\"http://site/asasas\"> Checar resultado<br></a><a href=\"http://site/puxar.php\"> Veja aqui </a> ";

echo "<input type=\"hidden\" name=\"ncarts\" value=\"$ncarts\"> 
<input type=\"hidden\" name=\"npedras\" value=\"$npedras\"> </form> </body></html>";

 ?>

The variables that i've mentioned are $npedras and $carts.

And the mentioned puxar.php on the form action is:

<?php
$ncarts = $_POST["ncarts"];
$npedras = $_POST["npedras"];
$todos_numeros = file ("cartelas.txt"); 
foreach ($todos_numeros as $r){
echo $r . "<br>";
}
echo $ncarts;
?>

What happens is that the $ncarts doesn't arrive on the last file. I'm exhausted of looking for typing errors... Someone help me?? Thanks!

$_POST is only populated when sending form data via HTTP POST. If the request is not sent via POST that array will be empty. Each page load is a fresh page request so it will be empty unless the next request includes POST data.

To get data from one page to another you need to use a more (semi)permanent storage method like sessions.