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 Link to comment https://forums.phpfreaks.com/topic/60169-entering-the-duplicate-record/ 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. Link to comment https://forums.phpfreaks.com/topic/60169-entering-the-duplicate-record/#findComment-299362 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. Link to comment https://forums.phpfreaks.com/topic/60169-entering-the-duplicate-record/#findComment-299385 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 Link to comment https://forums.phpfreaks.com/topic/60169-entering-the-duplicate-record/#findComment-300048 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 Link to comment https://forums.phpfreaks.com/topic/60169-entering-the-duplicate-record/#findComment-300153 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 Link to comment https://forums.phpfreaks.com/topic/60169-entering-the-duplicate-record/#findComment-300195 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.