我正在为在线商店构建一个基本的注册和登录系统。
我是一个完整的 php 新手,正在努力理解 php 的阅读方面。我的注册验证正常并且正在写入正确的文件。每个用户都需要使用唯一的电子邮件地址进行注册,但我不确定如何进行此检查。
<?php
// form filled out correctly
// assign all POSTed variables
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$address = $_POST['address'];
$email = $_POST['email'];
$sex = $_POST ['sex'];
$age = $_POST ['age'];
$pwd = $_POST ['pwd'];
// form validation such as all fields are filed in and email correct format
$fp = fopen("user.txt", "r");
//Output a line of the file until the end is reached
//combine string for output
$output_string = "Firstname: " .$fname ."\t"
."Lastname: " .$lname ."\t"
."Address: " .$address ."\t"
."Email: " .$email ."\t"
."Sex: " .$sex ."\t"
."Age: " .$age ."\t"
."Password: " .$pwd ."\n";
//write user to user.txt
$fp = fopen ("user.txt", "a");
fwrite ($fp, $output_string);
fclose($fp);
echo "<p> Your registration was successful! </p>";
echo "<h3> <a href=\"login.php\"> Login here </h3>";
?>