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

查看:225
本文介绍了使用PHP从HTML表单写入文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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>

这篇关于使用PHP从HTML表单写入文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆