【发布时间】:2015-09-27 21:09:42
【问题描述】:
我对 php 很陌生(3.5 周),我正在为我正在学习的 php 课程做一个项目。我已经在这个 php 文件上工作了好几天了,我正处于崩溃的边缘。这是我想要实现的目标:
“使用为保龄球锦标赛注册保龄球运动员的表格创建文档。使用单个文本文件将每个保龄球运动员的信息保存在单独的行中。包括保龄球运动员的姓名、年龄和平均值,以逗号分隔。确保 Projects 目录对每个人都有读写权限。”
我已成功创建表单,并且我认为我的变量设置正确。我想我需要使用一个数组来存储基于用户输入的每个变量。我试过写这个,我打破了一切。这是我到目前为止的代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>List of Bowlers</title>
<meta http-equiv="content-type"
content="text/html; charset=iso-8859-1" />
</head>
<body>
<h1 style="text-transform: uppercase; color: #666666; font-weight: 400; font-size: 1.5em; letter-spacing: 5px;">Register for the upcoming bowling tournament</h1>
<?php
if (isset($_POST['first_name']) && isset($_POST['last_
name'])) {
$BowlerFirstName = addslashes($_POST['first_name']);
$BowlerLastName = addslashes($_POST['last_name']);
$BowlerAge = addslashes($_POST['bowler_age']);
$BowlerAverage = addslashes($_POST['bowler_average']);
$NewBowler = "$BowlerLastName, $BowlerFirstName, $BowlerAge, $BowlerAverage\r\n";
$BowlersFile = "bowlers.txt";
if (file_put_contents($BowlersFile, $NewBowler,
FILE_APPEND) > 0)
echo "<p>" . stripslashes($_POST['first_name']) .
" " . stripslashes($_POST['last_name']) .
" has been registered for the upcoming bowling tournament.</p>\n";
else
echo "<p>An error has occurred in your registration. Please try again.</p>";
} else
echo "<p>To successfully enter the upcoming bowling tournament, enter
your first and last name and click the Register
button.</p>";
?>
<form action="bowling_names.php" method="POST">
<p>First Name: <input type="text" name="first_name"
size="30" /></p>
<p>Last Name: <input type="text" name="last_name"
size="30" /></p>
<p>Age: <input type="text" name="bowler_age"
size="30" /></p>
<p>Average: <input type="text" name="bowler_average"
size="30" /></p>
<p><input type="submit" value="Register" /></p>
</form>
<?php
$BowlersList = readfile("bowlers.txt");
echo $BowlersList;
?>
</body>
</html>
我真的在尝试学习这里的概念。如果您愿意提供帮助,请解释我哪里出错了。我非常感谢任何帮助!
【问题讨论】:
-
看起来,SE domehow 不喜欢像你这样的问题 :-( 这类“概念”问题的主要问题是它们往往有 200 页长而没有可见的结尾。一个简短的概念性问题足以让你继续的答案将是一个很好的答案,但我几乎可以肯定它不会让你开心。我建议在任何地方开始使用谷歌。你肯定会遇到一个新的、更具体的问题,然后回来吧。
标签: php html forms text readfile