简体   繁体   English

无法使此简单的PHP代码正常工作/留言簿脚本

[英]Can't get this simple PHP code to work / guestbook script

I found a php script used for building your own guestbook which I tried to make into a simple page for reporting sales. 我找到了一个用于构建自己的留言簿的php脚本,我试图将其制作成一个简单的销售报告页面。 Please take a look at the code because something is wrong, I end up with a WSoD. 请看一下代码,因为出了点问题,我得到了一个WSoD。

I just want some different fields and make these appear on the same page (preferably with auto-date function) when Save is pressed. 我只想要一些不同的字段,并在按“保存”时使它们显示在同一页面上(最好使用自动日期功能)。

<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>

Problem 1 问题1

You have extra ) s in your if statement: 你有多余的)在你的S if语句:

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

... should be... ... 应该...

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

Problem 2 问题2

You also overwrite the same variable a few times, which results in $date and $company being empty: 您还会覆盖相同的变量几次,导致$date$company为空:

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

... should be... ... 应该...

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM