Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在php中使用按钮将值传输到文本文件_Php_Html - Fatal编程技术网

在php中使用按钮将值传输到文本文件

在php中使用按钮将值传输到文本文件,php,html,Php,Html,我需要你的帮助。Atm-Im编程一个php脚本,该脚本将单个文本输入从HTML输入框写入文本文件。代码如下: <center> <form name="form" action="" method="get"> <input type="text" name="APIkey" id="APIkey" value="API Key"> </form> </center> 网站用户应在文本框中输入API

我需要你的帮助。Atm-Im编程一个php脚本,该脚本将单个文本输入从HTML输入框写入文本文件。代码如下:

<center>
    <form name="form" action="" method="get">
        <input type="text" name="APIkey" id="APIkey" value="API Key">
    </form>
</center>

网站用户应在文本框中输入APIkey,然后按下按钮将APIkey传输到以下php脚本,并将其写入APIkey.txt

<?php
$myfile = fopen("APIkey.txt", "w") or die("Unable to open file!");
$txt = APIkey;
fwrite($myfile, $txt);
fclose($myfile);
?>


感谢您的帮助……

您需要对代码进行一些更改,使其能够按照您的要求工作。在php文件的同一目录中创建一个文本文件。下面是简单的方法

<center>
  <form name="form" action="" method="post">
    <input type="text" name="APIkey" id="APIkey" value="API Key">
    <input type="submit" value="submit" name="submit" >
  </form>
</center>

<?php 
if(isset($_POST['submit']))
{
  $myfile = fopen("APIkey.txt", "w") or die("Unable to open file!");
  $txt = $_REQUEST['APIkey'];
  fwrite($myfile, $txt);
  fclose($myfile);
}
?>

我认为是时候阅读关于PHP请求的优秀教程了。


您已使用GET方法发送数据,但对于长文本,不建议通过url传递

<form name="form" action="" method="post">
    <input type="text" name="APIkey" id="APIkey" value="API Key">
</form>

    <?php

    // For information
    var_dump($_POST);

    if(isset($_POST["APIkey"]) {

    $myfile = fopen("APIkey.txt", "w") or die("Unable to open file!");
    $txt = $_POST["APIkey"];
    fwrite($myfile, $txt);
    fclose($myfile);

   }
?>


您可以使用AJAX方法将API发送到给定的代码。如果它有帮助,您可以将答案作为helpfullYea,让所有人发送敏感信息,例如带有GET请求的apikeys^^
<form name="form" action="" method="post">
    <input type="text" name="APIkey" id="APIkey" value="API Key">
</form>

    <?php

    // For information
    var_dump($_POST);

    if(isset($_POST["APIkey"]) {

    $myfile = fopen("APIkey.txt", "w") or die("Unable to open file!");
    $txt = $_POST["APIkey"];
    fwrite($myfile, $txt);
    fclose($myfile);

   }
?>