hey guys
coding a website atm that allows you to, once youve registered, change your account details. the user data is stored in a text file line by line, with each user having a varying number of characters for username, password, name, surname, phone number, email etc. these details are all separated by "|".
my problem is that when the user adjusts their information, the line their data is on in the text file either doesnt get overridden fully (if their new input of characters is less than originally) and the old data is pushed to the new line because of a "\n", or it overwrites information on the next line (if their new input of characters is more than originally) and then does a new line.
tried to do a cutline program, but thats a bit beyond me
thanks guys
CODE:
function cutline($file, $line_no =-1) { //not working but im guessing itd be something along those lines
$strip_return = false;
$size = count($data);
if($line_no == -1) {
$skip = $size-1;
} else {
$skip = $line_no-1;
}
for($line = 0; $line < $size; $line++) {
if($line != $skip) {
fputs($file, $data[$line]);
} else {
$strip_return = true;
}
}
return $strip_return;
}
if (isset($_POST['adjust'])) {
$file = fopen("members.txt", 'r+');
while (!feof($file)) {
if ($data[0] == $_SESSION['type'] && $data[1] == $_SESSION['password'] && $data[5] == $_SESSION['ph'] && $data[7] == $_SESSION['email']) {
echo "found user";
if ($_POST['new_username'] == "") {
$new_username = $_SESSION['type'];
} else {
$new_username = $_POST['new_username'];
$_SESSION['type'] = $new_username;
}
if ($_POST['new_password'] == "") {
$new_password = $_SESSION['password'];
} else {
$new_password = $_POST['new_password'];
$_SESSION['password'] = $new_password;
}
if ($_POST['new_ph'] == "") {
$new_ph = $_SESSION['ph'];
} else {
$new_ph = $_POST['new_ph'];
$_SESSION['ph'] = $new_ph;
}
if ($_POST['new_address'] == "") {
$new_address = $_SESSION['address'];
} else {
$new_address = $_POST['new_address'];
$_SESSION['address'] = $new_address;
}
if ($_POST['new_email'] == "") {
$new_email = $_SESSION['email'];
} else {
$new_email = $_POST['new_email'];
$_SESSION['email'] = $new_email;
}
fseek($file, $line);
cutline($file, $line);
$data = fwrite($file, $new_username."|".$new_password."|".$_SESSION['name']."|".$_SESSION['surname']."|".$_SESSION['dob']."|".$new_ph."|".$new_address."|".$new_email."|".$_POST['new_reglevel']."|".$_POST['new_regtime']."\n");
fclose($file);
exit();
} else {
$line+1;
}
} fclose($file);
}
TEXT FILE (members.txt):
jimBob|jimBob|Jim|Bob|20/02/1965|95555555|Mentone|jim_bob@gmail.com|Gold|1 Year
admin|123|admin|admin1|-|-|-|admin1@gmail.com|-|-
blah|blah|-|-|-|-|Gold|Lifetime
eg - TEXT FILE after user data changed and less characters are inputted:
jim|abc|Jim|Bob|20/02/1965|95555555|blahaha|jim_bob@gmail.com|Gold|1 Year
ar
admin|123|admin|admin1|-|-|-|admin1@gmail.com|-|-
blah|blah|-|-|-|-|Gold|Lifetime