无法让这个简单的PHP代码工作/留言簿脚本



我找到了一个php脚本用于构建您自己的留言簿,我试图使其成为一个简单的页面报告销售。请看看代码,因为有些地方是错误的,我最终与WSoD。

我只是想要一些不同的领域,并使这些出现在同一页(最好与自动日期功能)保存时按下。

<html>
<head><title>Reports</title></head>
<body>
<h1>Reports</h1>
<h2>Please fill in the form below and click Save.</h2>
<form action="" method="POST">
<input type="text" name="user" placeholder="Name" />
<br />
<input type="text" name="date" placeholder="Date" />
<br />
<input type="text" name="company" placeholder="Company" />
<br />
<textarea cols="40" rows="5" name="note" placeholder="Report" wrap="virtual"></textarea>
<br />
<input type="submit" name="submit" value="Save" />
</form>
<?php
if (isset($_POST['submit'])){
$user = $_POST['user'];
$user = $_POST['date'];
$user = $_POST['company'];
$note = $_POST['note'];
if(!empty($user) && !empty($date)) && !empty($company)) && !empty($note)) {
$msg = $user . ' <br /> ' . $date . ' <br /> ' . $company . ' <br /> ' . $note;
//will open a file
$fp = fopen("report.txt","a") or die("Can't open file");
//will write to a file
fwrite($fp, $msg."n");
fclose($fp);
}
}
?>
<h2>Old reports:</h2>
<?php
$file = fopen("report.txt", "r") or exit("Unable to open file!");
//Output a line of the file until the end is reached
while(!feof($file))
  {
  //will return each line with a break
  echo fgets($file). '<br />';
  }
fclose($file);
?> 
</body>
</html>

问题1

您的if语句中有额外的):

if(!empty($user) && !empty($date)) && !empty($company)) && !empty($note)) {

…应该…

if(!empty($user) && !empty($date) && !empty($company) && !empty($note)) {

问题2

您还将同一变量重写几次,这导致$date$company为空:

$user = $_POST['user'];
$user = $_POST['date'];
$user = $_POST['company'];
$note = $_POST['note'];

…应该…

$user = $_POST['user'];
$date = $_POST['date'];
$company = $_POST['company'];
$note = $_POST['note'];

相关内容

  • 没有找到相关文章

最新更新