hi,
im a bit new to php programming, and im trying to make this:
- user enters data on webpage and i store them to a txt file (this worked easily ...)
- then i wanted to compare the string that users add to already saved data in txt files. so reading line by line .... it is suppose to be working like this: if there is a duplicate entery, close file and echo "duplicate entery". i use strcmp to compare two string and its kind a frustrating, cause i get in infinty loop i guess and lots o new, same enterys in the txt file. i got stuck here and wonder if someone could help ....
this is my code ....
<?php
$text = $_GET['email'];
$text1 = $_GET['sex'];
$text2 = $_GET['age'];
$dates = date("d.m.Y H");
$savestring = "\n" . $dates . ";" . $text . ";" . $text1 . ";" . $text2 ;
$fp = fopen("myFile.txt", 'r');
while (!feof($fp)) {
$line = fgets($fp);
if(strcmp($savestring,$line)==0) {
echo "<h1>Duplicate entery.</h1>";
fclose($fp);
}
else {
fclose($fp);
$fp1 = fopen("myFile1.txt", 'a');
fwrite($fp1, $savestring);
echo "<h1>Success. U have been added to list.</h1>";
}
}
?>