Answer the question
In order to leave comments, you need to log in
Why doesn't php compare?
When there is more than 1 nickname in the nick.txt file, then he does not understand that the nickname has been repeated, what to do? I have already tried everything.
<?php
require "index3.php";
if(isset($_POST["text"]) && isset($_POST["password"])){
$fd = fopen("nick.txt","r");
$writess = 0;
$nick = $_POST["text"];
while(!feof($fd)){
$str = htmlentities(fgets($fd));
if($str == $nick){
$writess = 1;
}
}
fclose($fd);
echo $writess;
if($writess == 0){
$fd = fopen("nick.txt","a");
fwrite($fd,"\n");
fwrite($fd,$_POST["text"]);
fclose($fd);
$fd = fopen("passwords.txt","a");
fwrite($fd,"\n");
fwrite($fd,$_POST["password"]);
fclose($fd);
echo "Вы зарегестрированны!";
}
if($writess == 1){
echo "Пользователь уже зарегестрирован!";
}
}
?>
<html>
<head>
<meta charset = "utf-8">
<title>Site</title>
</head>
<body>
<form id = "form" method = "POST">
<div id = "div" align = "center">
<p>Register.</p>
<input id = "text" required type = "text" name = "text" placeholder = "Nick">
<input id = "text2" required type = "text" name = "password" placeholder = "Password">
<input id = "text3" type = "submit" name = "submit" value = "Register">
</div>
</form>
<style>
#form{
position: fixed;
top: 40%;
left: 40%;
width: 200px;
height: 117px;
border: 1px solid black;
}
#div{
width: 100%;
height: 100%;
}
#text{
width: 100%;
}
#text2{
width: 100%;
}
#text3{
width: 100%;
}
</style>
</body>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question