[英]Can't get PHP script to write user input to text file
I cannot get this simple PHP
script to grab the data from the HTML
form. 我无法获得这个简单的PHP
脚本来从HTML
表单中获取数据。 The script throws this warning: 该脚本引发以下警告:
(Notice: Use of undefined constant 'email' - assumed ''email'' in /absolute/fullpath/godaddy/frustration/html/mail.php on line 5) (注意:使用未定义的常量'email'-在第5行的/absolute/fullpath/godaddy/frustration/html/mail.php中假定为“ email”)
Longer explanation: I am writing this simple PHP
script for my buddy's website. 更长的解释:我正在为我的好友的网站编写此简单的PHP
脚本。 It is supposed to collect the email address and write it to a text file. 应该收集电子邮件地址并将其写入文本文件。 I decided to go this route instead of utilizing any type of database. 我决定走这条路,而不是利用任何类型的数据库。 I have the email.txt
file and PHP
script both on the root directory of the webserver. 我在Web服务器的根目录上都有email.txt
文件和PHP
脚本。 We're using GoDaddy
to host the site. 我们正在使用GoDaddy
托管网站。 I made sure GoDaddy
had PHP
enabled and that no restrictive settings were present. 我确保GoDaddy
已启用PHP
,并且没有限制性设置。
I changed the permissions of both the script and the text file to 666
. 我将脚本和文本文件的权限都更改为666
。 I've concluded that the script doesn't grab the data that is being posted from the HTML
form. 我得出的结论是,该脚本无法捕获从HTML
表单发布的数据。 I came to this conclusion because I tested the fwrite
function and it easily wrote to the text file (email.txt)
without a hiccup. 之所以得出这个结论,是因为我测试了fwrite
函数,并且可以轻松地将其写入文本文件(email.txt)
。
I've spent only a few hours over the past two weeks trying to complete this, but I feel like I have exhausted all of my options. 在过去的两个星期中,我仅花了几个小时就完成了此任务,但我觉得我已经用尽了所有的选择。 I've searched far and wide through Google and noticed other people with similar issues. 我通过Google进行了广泛搜索,发现其他人也遇到类似问题。 However, they fixed their issue by adding full-paths for the text file, changing permissions, etc. 但是,他们通过添加文本文件的完整路径,更改权限等解决了问题。
Whenever I input an email address into the textbox and hit submit nothing is written to the email.txt
file, just an empty text file. 每当我在文本框中输入电子邮件地址并点击“提交”时,都不email.txt
任何内容写入email.txt
文件,只是一个空的文本文件。
Thank you in advance for any feedback or help. 预先感谢您的任何反馈或帮助。 It's much appreciated! 非常感谢!
<form id="emaillist" name="email" method="post" action="mail.php">
<label for="mailList"></label>
<input type="text" name="email" id="email" placeholder="Email Address" />
<input type="submit" name="submitMail" id="submitMail" value="Submit" />
</form>
<?php
ini_set('display_errors', 1); // show errors
error_reporting(-1); // of all levels
date_default_timezone_set('UTC'); // PHP will complain about on this error level
$emailaddr = $_POST[’email’];
$fp = fopen('/full/path/totextfile/html/email.txt', 'a');
fwrite($fp, $emailaddr);
fclose($fp);
echo 'Thank you!';
phpinfo();
?>
Correct: 正确:
$emailaddr = $_POST[’email’]; // back ticks are used to enclose, incorrect.
To: 至:
$emailaddr = $_POST['email']; // single quotes are used to enclose, correct.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.