php中的$_POST没有值


$_POST in php not having a value

我创建了两个php文件。第一个是encrypt.php,它将文本区域发送到handleData.php。目前,这只是将输入保存到文本文件中,但即使这样也不起作用。文本文件保持原样,post似乎没有传递任何数据。我也尝试过明确地回显数据,但它仍然是空白的。为什么邮政没有发送任何数据?我已经做了所有正确的事情,就我所能看到的和命名的文本区域,但它拒绝工作

encrypt.php

<form method="POST" action="handleData.php">                                                                                                                                   
    <p><textarea name="plaintext" placeholder="Enter text to encrypt" rows="10" cols="50"><?php echo exec("cat input.txt")?></textarea></p>                                      
    <p><textarea name="ciphertext" placeholder="Enter text to decrypt" rows="10" cols="50"><?php echo exec("cat output.txt")?></textarea></p>                                    
    <p><input type="submit" value="Encrypt/Decrypt" onClick="location.reload()"></p>                                                                                             
</form> 

handleData.php

<?php                                                                                                                                                                                
    $num = "3128342308234";                                                                                                                                                           
    $plain = (isset($_POST['plaintext'])) ? htmlspecialchars($_POST['plaintext']) : 'test';                                                                                           
    $cipher = (isset($_POST['ciphertext'])) ? $_POST['ciphertext'] : '';                                                                                                              
    echo $_POST['plaintext'];                                                                                                                                                         
    exec("$plain >> input.txt");                                                                                                                                                      
    $command = "encryptPoly ".$num." ".$plain;                                                                                                                                        
    exec("rm output.txt");                                                                                                                                                            
    exec($command." >> output.txt");                                                                                                                                                  
?>

您正在重新加载页面,因此没有提交,

<p><input type="submit" value="Encrypt/Decrypt" onClick="location.reload()"></p>  

只需删除onClick:

<p><input type="submit" value="Encrypt/Decrypt"></p> 

并确保此操作与当前文件的名称相同。

<form method="POST" action="handleData.php">   

你可以试试这个:

<?php                                                                                                                                                                                
$num = "3128342308234";                                                                                                                                                           
$plain = (isset($_POST['plaintext'])) ? htmlspecialchars($_POST['plaintext']) : 'test';                                                                                           
$cipher = (isset($_POST['ciphertext'])) ? $_POST['ciphertext'] : '';                                                                                                              
echo $_POST['plaintext'];                                                                                                                                                         
exec("$plain >> input.txt");                                                                                                                                                      
$command = "encryptPoly ".$num." ".$plain;                                                                                                                                        
exec("rm output.txt");                                                                                                                                                            
exec($command." >> output.txt");                                                                                                                                                  
?>

至:

<?php                                                                                                                                                                                
$num = "3128342308234";                                                                                                                                                           
$plain = (isset($_POST['plaintext'])) ? htmlspecialchars($_POST['plaintext']) : 'test';                                                                                           
$cipher = (isset($_POST['ciphertext'])) ? $_POST['ciphertext'] : '';                                                                                                              
echo $_POST['plaintext'];                                                                                                                                                         
exec("$plain >> input.txt");                                                                                                                                                      
$command = "encryptPoly ".$num." ".$plain;                                                                                                                                        
exec("rm output.txt");                                                                                                                                                            
exec($command." >> output.txt");
header('Location: ' . $_SERVER['HTTP_REFERER']);// Go back to previous page.  
?>