我正在尝试这样做,以便每次按下提交按钮时,都会创建一个包含文本框信息的txt文件。提交表单后,它会重定向到不同的html文件。但这不起作用
这是我的PHP代码(文件名:process.php)
<?php
$form = fopen("forms/openhouse_signup.txt", "w") or die("Error: Missing Forms on Server!");
if (!empty($_POST)){
$txt = "Parent's Name: ".$_POST['parentN']."\n";
fwrite($form, $txt);
$txt = "Email Address: ".$_POST['email']."\n";
fwrite($form, $txt);
$txt = "Postal Code: ".$_POST['postal']."\n";
fwrite($form, $txt);
$txt = "Phone Number: ".$_POST['phone']."\n";
fwrite($form, $txt);
$txt = "Child's Name: ".$_POST['childN']."\n";
fwrite($form, $txt);
$txt = "Child's Age: ".$_POST['childA']."\n";
fwrite($form, $txt);
$txt = "\n ----------------------------- \n";
fwrite($form, $txt);
fclose($form);
header('Location: done.html');
}
?>
我的HTML代码(文件名:signup.html)
<h2 style="font-family:Arial, Sans-serif">Please Fill In The Following Boxes To Sign Up</h2>
<form style="font-family:Arial, sans-serif; font-size:12pt" name="input" action="process.php" method="POST">
Full Name of Parent:<br>
<input class="txtbox" type="text" name="parentN"><br><br>
Email Address:<br>
<input class="txtbox" type="text" name="email"><br><br>
Postal Code:<br>
<input class="txtbox" type="text" name="postal"><br><br>
Phone Number:<br>
<input class="txtbox" type="text" name="phone"><br><br>
Full Name of Child:<br>
<input class="txtbox" type="text" name="childN"><br><br>
Age of Child:<br>
<input class="txtbox" type="text" name="childA"><br><br>
<input type="submit" value="Sign Up!">
</form>
答案 0 :(得分:1)
我已经测试了你的代码,它运行得很好。所以到目前为止这么好,然后我发现这个问题我认为是你的。您可能无权在文件中打开和写入。要解决此问题,您需要将其chmod更改为777。 您可以通过命令行执行此操作:
chmod 777 filename.php
或PHP指令,如果您愿意:
chmod(filename.php, 777);
chmod到777表单文件夹,以便能够在此文件夹中创建任何内容。
然后我再次运行代码,它运行得很好。以下是.txt
文件的输出:
Parent's Name: a
Email Address: b
Postal Code: c
Phone Number: de
Child's Name: e
Child's Age: f
-----------------------------
有关chmod
的更多文档,请参阅:http://php.net//manual/fr/function.chmod.php和http://en.wikipedia.org/wiki/Chmod
答案 1 :(得分:0)
在添加&#39;值&#39;后尝试text-field中的属性如下:
<form name="input" action="process.php" method="POST">
Full Name of Parent:<br>
<input class="txtbox" type="text" value="" name="parentN"><br><br>
Email Address:<br>
<input class="txtbox" type="text" value="" name="email"><br><br>
Postal Code:<br>
<input class="txtbox" type="text" value="" name="postal"><br><br>
Phone Number:<br>
<input class="txtbox" type="text" value="" name="phone"><br><br>
Full Name of Child:<br>
<input class="txtbox" type="text" value="" name="childN"><br><br>
Age of Child:<br>
<input class="txtbox" type="text" value="" name="childA"><br><br>
<input type="submit" value="Sign Up!">
</form>