You could add the current contents of the file to the top when it is being rewritten I guess... I am going in about 2 minutes so no time :/
Printable View
You could add the current contents of the file to the top when it is being rewritten I guess... I am going in about 2 minutes so no time :/
Not tested, hopefully should work. Updates or inserts into DB and overwrites or creates a new file for the name. Change any form variables and DB stuff, I also assumed you'd have a config file or something you could include:
PHP Code:<?php
if($_POST['details']) {
$name = $_POST['name'];
$x = $_POST['x_coord'];
$y = $_POST['y_coord'];
if(mysql_num_rows(mysql_query("SELECT * FROM `db_name` WHERE `name` = '$name'")) > 0) {
$upd = mysql_query("UPDATE `db_name` SET `x_cord` = '$x' AND `y_cord` = '$y' WHERE `name` = '$name'") or die(mysql_error());
}
else {
$ins = mysql_query("INSERT INTO `db_name` (`name`, `x_cord`, `y_cord`) VALUES ('$name', '$x', '$y')") or die(mysql_error());
}
$file = $name . '.txt';
$f_op = fopen($file);
$string = 'x_cord = ' . $x . '\n';
$string .= 'y_cord = ' . $y;
fwrite($f_op, $string);
fclose($f_op);
}
?>