这是海报点php
<?php
$FILENAME = "poster.php";
$txt = "data.txt";
if (isset($_POST['field1']) && isset($_POST['field2'])) { // check if both
fields are set
$fh = fopen($txt, 'a');
$txt=$_POST['field1'].' - '.$_POST['field2'];
fwrite($fh,$txt); // Write information to the file
fclose($fh); // Close the file
}
?>
这是我的HTML表单
<!DOCTYPE html>
<html>
<head>
<title>Field 1 & 2</title>
</head>
<body>
<form action="poster.php" method="post">
What is your name?<br>
<input type="text" name="field1"><br>
<input type="text" name="field2"><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
当我把它放在调试器中时,我尝试了所有这些工作,它说文件应该在第一行结束。当我运行文件时,我得到的是一个白色屏幕。我迫切需要帮助。
答案 0 :(得分:0)
表单的操作属性应该是您提交表单的文件名。
<form action="action.php" method="post">
这是&#39; action.php&#39;但你必须在海报点php上提交。
答案 1 :(得分:0)
请检查:
<form action="poster.php" method="post">
表单操作将是您的主文件名(poster.php),在表单发布后,您可以轻松地获取poster.php文件中的所有表单字段数据。
你知道这个文件名 - &gt; poster dot php的意思是poster.php?
答案 2 :(得分:0)
在poster.php文件中附加表单数据后,您没有写任何内容。您可以通过以下方式获取文件内容......
Html表格:
<!DOCTYPE html>
<html>
<head>
<title>Field 1 & 2</title>
</head>
<body>
<form action="poster.php" method="post">
What is your name?<br>
<input type="text" name="field1"><br>
<input type="text" name="field2"><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
并在poster.php
<?php
$FILENAME = "poster.php";
$txt = "data.txt";
if (isset($_POST['field1']) && isset($_POST['field2'])) { // check if both
//fields are set
$fh = fopen($txt, 'a');
$txt=$_POST['field1'].' - '.$_POST['field2'].PHP_EOL;
fwrite($fh,$txt); // Write information to the file
fclose($fh); // Close the file
echo file_get_contents("data.txt");
}
?>
根据要求,在单个文件中编写PHP代码和HTML代码,并在以下代码中删除表单的action属性...
<?php
//$FILENAME = "poster.php";
$txt = "data.txt";
if (isset($_POST['field1']) && isset($_POST['field2'])) { // check if both
//fields are set
$fh = fopen($txt, 'a');
$txt=$_POST['field1'].' - '.$_POST['field2'].PHP_EOL ;
fwrite($fh,$txt); // Write information to the file
fclose($fh); // Close the file
//echo file_get_contents("data.txt");
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Field 1 & 2</title>
</head>
<body>
<form action="" method="post">
What is your name?<br>
<input type="text" name="field1"><br>
<input type="text" name="field2"><br>
<input type="submit" value="Submit">
</form>
</body>
</html>