Jump to content

Entering the duplicate record


sandy1028

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.