Current location: Hot Scripts Forums » Programming Languages » PHP » Only add if not found...


Only add if not found...

Reply
  #1 (permalink)  
Old 07-01-09, 05:21 PM
peuplarchie's Avatar
peuplarchie peuplarchie is offline
Newbie Coder
 
Join Date: Nov 2008
Posts: 64
Thanks: 1
Thanked 0 Times in 0 Posts
Post Only add if not found...

Good day to you all,
My code is looking for user name in a file, if match found, do nothing, if no match found, add to list.

Right now, it add anyway !

PHP Code:



$activeadmlist 
"user_list.txt";
$pos strpos($activeadmlist$_SESSION['username']);

if (
$pos === false) {

$output$_SESSION['username']."\n";
$newfile="user_list.txt";
$file fopen ($newfile"a");
fwrite($file$output);
fclose ($file); 


} else {
    


Thanks!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 07-01-09, 05:23 PM
=OTS=G-Man =OTS=G-Man is offline
Newbie Coder
 
Join Date: Jun 2009
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Dude you really need to just post 1 topic for a problem

http://www.hotscripts.com/forums/php...text-file.html
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 07-01-09, 05:30 PM
peuplarchie's Avatar
peuplarchie peuplarchie is offline
Newbie Coder
 
Join Date: Nov 2008
Posts: 64
Thanks: 1
Thanked 0 Times in 0 Posts
it is a different problem.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 07-01-09, 05:32 PM
=OTS=G-Man =OTS=G-Man is offline
Newbie Coder
 
Join Date: Jun 2009
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
not really, the problem is your still checking the file name for the username, not the actual file data.

I posted a solution in your original post
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 07-02-09, 03:45 PM
Keith's Avatar
Keith Keith is offline
Community Liaison
 
Join Date: Feb 2004
Posts: 1,232
Thanks: 1
Thanked 11 Times in 11 Posts
You need to get the contents of the file:
PHP Code:

// change this:
$pos strpos($activeadmlist$_SESSION['username']);

// to this:
$pos strpos(file_get_contents($activeadmlist), $_SESSION['username']); 
Otherwise, you are looking for the value of $_SESSION['username'] in the string user_list.txt.
__________________
The toxic ZCE
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Multi script PayPal add to cart order form Tito1 JavaScript 5 02-23-09 05:21 AM
Read from file, add to list Saturn Job Offers & Assistance 10 02-08-09 11:00 PM
Add another two fields blinn_shade JavaScript 1 10-15-07 11:35 PM
Assembler Coding downsouth The Lounge 1 12-18-06 03:58 AM
Alter Table Help DDRcasey PHP 0 06-14-05 01:08 AM


All times are GMT -5. The time now is 06:27 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.