|
Posted by programming on 04/25/07 00:54
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);
}
}
?>
Navigation:
[Reply to this message]
|