Oh thanks, but I think I have a problem now. Either I made a mistake in installing that script or there is some problem(I think I made a mistake but I am not sure). It doesn't update the name but adds a new line before the first line of the file.
I mean that if the database.php looks like this at first:
PHP Code:
<?php exit()?>
Shachi,test,shachibista[at]gmail[dot]com,nepal
After running that script it becomes:
PHP Code:
<?php exit()?>
Shachi,test,shachibista[at]gmail[dot]com,nepal
I don't know what the problem is but for testing purposes I just made a new file and tried executing that script. The new file looks sth like this:
PHP Code:
<?php
define('DATABASE_FILE', 'database_fake.php');
define('SEPARATOR', ',');
define('LINEBREAK', "\n");
define('USERNAME', 0);
define('PASSWORD', 1);
define('EMAIL', 2);
define('COUNTRY', 3);
define('ZIP', 4);
function updateUser($ccol, $cval, $col, $val) {
$ret = 0;
$lines = file(DATABASE_FILE);
for($i = 0; $i < count($lines); ++$i) {
$cline = explode(SEPARATOR, $lines[$i]);
if($cline[$ccol] == $cval) {
$cline[$col] = $val;
$lines[$i] = implode(SEPARATOR, $cline);
++$ret;
}
}
$f = fopen(DATABASE_FILE, 'w');
fwrite($f, implode("\n", $lines));
fclose($f);
return $ret;
}
updateUser(USERNAME, 'Shachi', COUNTRY, 'Nepal');
?>
Bookmarks