>我创建了一个HTML表单,该表单应该使用PHP将输入的文本提交到.txt文件中,但它只创建了一个空行,我不知道问题是什么。
非常感谢帮助!
<form class="form-inline validate" name="form1" method="post" action="signup.php" target="_blank" novalidate>
<div class="row no-gutter">
<div class="col-sm-9">
<input type="email" value="" name="mail" class="form-control" placeholder="Subscribe to our newsletter" required>
</div>
<div class="col-sm-3">
<input type="submit" value="SUBSCRIBE" name="Submit">
</div>
</div>
</form>
<?php
$username = $_POST['user'];
//the data
$data = "$emailn";
//open the file and choose the mode
$fh = fopen("users.txt", "a");
fwrite($fh, $data);
//close the file
fclose($fh);
print "User Submitted";
?>
如果你想接收邮件,请将你的php代码更改为
<?php
if(isset($_POST['Submit'])){
$email = $_POST['mail'];
//the data
$data = "$emailn";
//open the file and choose the mode
$fh = fopen("users.txt", "a+");
fwrite($fh, $data);
//close the file
fclose($fh);
print "User Submitted";
}
?>