2014-04-29 52 views
0

嗯,我在一个页面上有一个隐藏表单,只是为了向另一个php文件发送一个值。 第一个文件是:变量传输失败

<?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]."\r\n"; 
      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>"; 

?> 

,我已经提到的变量是$ npedras$车

而且在形式的行动提到puxar.php是:

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

什么情况是,在$ ncarts不会在最后一个文件到达。我厌倦了寻找打字错误...有人帮助我? 谢谢!

回答

0

$_POST仅在通过HTTP POST发送表单数据时填充。如果请求未通过POST发送,则该数组将为空。每个页面加载是一个新的页面请求,所以它将是空的,除非下一个请求包含POST数据。

要从一个页面获取数据到另一个页面,您需要使用更多(半)永久存储方法,如sessions