sandy1028 Posted July 16, 2007 Share Posted July 16, 2007 hi, The code inserts the duplicate record when i am writing to text file. <? $name=$_POST['name']; $address=$_POST['address']; $age=$_POST['age']; $email=$_POST['email']; $mobile=$_POST['mobile']; $residence=$_POST['residence']; $fp= fopen("phonedb.txt","r") or die("can't open file"); $lines = file('./phonedb.txt'); foreach ($lines as $line) { $text_line = explode(":" , $line); if($text_line[4]== $mobile) { fclose($fp); die(); } } $fp= fopen("data.txt","a") or die("can't open file"); $data="$name : $address : $age : $email : $mobile : $residence\n"; fwrite($fp, $data); fclose($fp); Still the duplicate record is getting inserted. Can anyone find out the problem and help with this Regards, Sandy Quote Link to comment Share on other sites More sharing options...
rameshfaj Posted July 16, 2007 Share Posted July 16, 2007 I think in file it is difficult to control the duplication but if u use the database concept then it would be easier. Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted July 16, 2007 Share Posted July 16, 2007 is there a reason why you are not using the same file??? - there are two file pointers in that script. Quote Link to comment Share on other sites More sharing options...
sandy1028 Posted July 17, 2007 Author Share Posted July 17, 2007 Hi, I am using files and storing the records in file. How to check the data present in that file or not Quote Link to comment Share on other sites More sharing options...
sandy1028 Posted July 17, 2007 Author Share Posted July 17, 2007 How to check the data is present in the text file or not....... Please help with this Quote Link to comment Share on other sites More sharing options...
sandy1028 Posted July 17, 2007 Author Share Posted July 17, 2007 Hi, To check from the txt file how to compare the values after explode $lines = file('./phonedb.txt'); $fp= fopen("phonedb.txt","r") or die("can't open file"); foreach ($lines as $line) { list($name1,$address1,$age1,$email1,$mobile1,$residence1) = explode(":" , $line); } if($mobile1 != $mobile){ $fp= fopen("phonedb.txt","a") or die("can't open file"); fwrite($fp, $data); fclose($fp); } Does not work. How to validate the from text file whether data exists or not Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.