By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,046 Members | 2,058 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,046 IT Pros & Developers. It's quick & easy.

edit lines in txt file

P: n/a
Hey all i am trying to write data that i have stored in a session back
to a member.txt, but i am unable to work out why it wont write. It
displays the data i have stored in the session ok, but it wont do the
next step! I have used a similiar script in another part of my web
page which works, but this one won't. From my understanding it has
something to do with if statement if($data[0] == $user_id), so i might
be trying to compare the previouis data to the current data stored in
the txt file properly. Any ideas?

Cheers,

Peri.
if(!isset($_POST[Submit])){
// Load the lines into an array; newlines are still attached
$fc=file("../username/member.txt");

foreach ($fc as $line)
{
$data = explode("|", $line);
if($data[0] == $_SESSION['valid_user'] ){
$user_id = $data[0];
$password = $data[1];
$firstname = $data[2];
$lastname = $data[3];
$email = $data[4];
}
}
}
else{
if(($firstname = $_POST["firstname"])
&&($password = $_POST["password"])
&&($lastname = $_POST["lastname"])
&&($email = $_POST["email"])){
$count = 0;
// Load the lines into an array; newlines are still
attached
$fc=file("../username/member.txt");
//open same file and use "w" to clear file
$f=fopen("../username/member.txt","w");
//loop through array using foreach
foreach ($fc as $line)
{
$str_line = $line;
$data = explode("|", $line);

if($data[0] == $user_id){

$str_new = $user_id."|".$password."|".
$firstname."|".$lastname."|".$email."\n";
fwrite($f,$str_new);
} else{
fwrite($f,$str_line);
}
}
if(($_POST["lastname"])&&($_POST["firstname"])==TRUE){
header("Location: ./user_home.php");
}
fclose($f);
}
}

?>

Apr 25 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"programming" <pe**************@gmail.comwrote in message
news:11**********************@t39g2000prd.googlegr oups.com...
| Hey all i am trying to write data that i have stored in a session back
| to a member.txt, but i am unable to work out why it wont write. It
| displays the data i have stored in the session ok, but it wont do the
| next step! I have used a similiar script in another part of my web
| page which works, but this one won't. From my understanding it has
| something to do with if statement if($data[0] == $user_id), so i might
| be trying to compare the previouis data to the current data stored in
| the txt file properly. Any ideas?
|
| Cheers,
|
| Peri.
well damn, dude. how many times are you going to post the same question. as
i recall, it was thouroughly hashed out in the last thread that issued from
the first post.
Apr 25 '07 #2

P: n/a
programming wrote:
Hey all i am trying to write data that i have stored in a session back
to a member.txt, but i am unable to work out why it wont write. It
displays the data i have stored in the session ok, but it wont do the
next step! I have used a similiar script in another part of my web
page which works, but this one won't. From my understanding it has
something to do with if statement if($data[0] == $user_id), so i might
be trying to compare the previouis data to the current data stored in
the txt file properly. Any ideas?

Cheers,

Peri.

Repeating the question till you get an answer YOU like? ;-)
Why not use a db for this? So much easier.

Sh.
Apr 25 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.