使用PHP从HTML表单写入文本文件(write to a text file from HTML form using PHP)

其他开发 IT屋
百度翻译此文   有道翻译此文
问 题

I wrote a html form just with an email field. I want to transfer that email that the user inputs into a text file on my web server.

When I click on the submit button I get a white screen. Nothing is written to my text file. I also want to redirect the user to another page when they click the submit button. Is this possible? I am a newbie.

<?php

$file = fopen("emaillist.txt","a+");
fwrite($file,$email);
fclose($file); 
print_r(error_get_last());

?>

<form action= "emaillist.php" method="post" name="email ">
<input type="text" name="email">
<br>
<br>
<input type="submit" name="email" value="submit"><br>
解决方案

Try this, Use different name for submit button also check if the submit button was pressed than write to file. You also didn't get the posted email values

<?php
if(isset($_POST['submit']))
{
    $email = $_POST['email'];
    $file = fopen("emaillist.txt","a+");
    fwrite($file,$email);
    fclose($file); 
    print_r(error_get_last());
}
?>
<form action= "" method="post" name="form">
<input type="text" name="email">
<br>
<br>
<input type="submit" name="submit" value="submit"><br>
</form>

本文地址:IT屋 » write to a text file from HTML form using PHP

问 题

我写了一个HTML表单,只是一个电子邮件字段。我想将用户
输入的电子邮件转移到我的Web服务器上的文本文件中。



当我点击提交按钮时,我会看到一个白色屏幕。没有任何内容写入我的文本文件。
我也想在点击提交按钮时将用户重定向到另一个页面。
这可能吗?



 <?php 

$ file = fopen(“emaillist.txt ”, “A +”);
fwrite($ file,$ email);
fclose($ file);
print_r(error_get_last());

?>

< form action =“emaillist.php”method =“post”name =“email”>
< input type =“text”name =“email”>
< br>
< br>
< input type =“submit”name =“email”value =“submit”>< br>

解决方案

试试这个,如果按下提交按钮而不是写入文件。您还未获得发布的电子邮件值



 < ;? php 
if(isset($ _ POST ['submit']))
{
$ email = $ _POST ['email'];
$ file = fopen(“emaillist.txt”,“a +”);
fwrite($ file,$ email);
fclose($ file);
print_r(error_get_last());
}
?>
< form action =“”method =“post”name =“form”>
< input type =“text”name =“email”>
< br>
< br>
< input type =“submit”name =“submit”value =“submit”>< br>
< / form>

本文地址:IT屋 » 使用PHP从HTML表单写入文本文件

官方微信
扫一扫关注IT屋
微信公众号搜索 “ IT屋 ” ,选择关注
与百万开发者在一起