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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.