PHP写入文本文件

时间:2015-11-16 04:04:01

标签: php html file

我正在为我在大学的课程开展一个项目,在这个项目中,我们必须将用户名和密码写入文本文件。但是,每当我尝试运行它时,信息都不会写入文档。任何建议都将非常感谢。

<?php
session_start();
$User = $_GET["user"];
$name = $_GET["name"];

$_SESSION["user"] = $User;
$_SESSION["name"] = $name;

$pass = rand(100000, 999999);
$file = fopen("accounts.txt", "w");
fwrite($file, $User);
fwrite($file, $pass);
fwrite($file, $name);

fclose($file);

$array = explode(" ", $name);

?>

<!DOCTYPE html>
<html>
<body>
<?php

$message = "Hello $name, you are registered. Your password is: $pass";
mail($User, "Homework Registration", $message);
print("All Done");
?>
</body>
</html> 

1 个答案:

答案 0 :(得分:1)

在您的try{ $conn = new PDO("mysql:host=$hostdb; dbname=$namedb", $userdb, $passdb); $conn->exec("SET CHARACTER SET utf8"); // Sets encoding UTF-8 $sql = "UPDATE parked SET weight = CASE WHEN DATEDIFF(NOW(), datecreated) <= 21 THEN 1 WHEN DATEDIFF(NOW(), datecreated) >= 22 AND DATEDIFF(NOW(), datecreated) < 42 THEN 2 WHEN DATEDIFF(NOW(), datecreated) >= 43 AND DATEDIFF(NOW(), datecreated) < 63 THEN 3 WHEN DATEDIFF(NOW(), datecreated) >= 63 AND DATEDIFF(NOW(), datecreated) < 84 THEN 4 WHEN DATEDIFF(NOW(), datecreated) >= 84 AND DATEDIFF(NOW(), datecreated) < 105 THEN 5 WHEN DATEDIFF(NOW(), datecreated) >= 105 THEN 6 END;"; $stmt = $conn->execute($sql); $conn = null; } catch(PDOException $e) { echo $e->getMessage(); } 语句之后关闭php标记

print

注意:

  1. 确保您有足够的权限来创建和编辑您执行的文件(accounts.txt)

  2. 如果您将其禁用,请启用print("All Done"); ?> ,以便您可以轻松调试