|
Posted by programming on 04/16/07 07:23
hi all,
here is the php code!
i am trying to use to 'edit' hyperlink to edit txt in member.txt.
Problem is that it reads the values ok into an array, however when i
attempt and update new values into the file, i get no results. Does
anybody know where i am going wrong????
<? session_start();
// Set updated content for user
if(!isset($_POST[Submit]))
{
// read content from file and place into array, this is used to put
initial content into form
$fc=file("../username/member.txt");
$userid_no = $_GET['record_id'];
$line = split("\|",$fc[$userid_no]);
$user_id = $line[0];
$password = $line[1];
$firstname = $line[2];
$lastname = $line[3];
$email = $line[4];
}
else
{
if(isset($_GET['record_id']))
{
// build record into string from post values
$update = $_POST['user_id'];
$update .= "|";
$update .= $_POST['password'];
$update .= "|";
$update .= $_POST['lastname'];
$update .= "|";
$update .= $_POST['firstname'];
$update .= "|";
$update .= $_POST['email'];
$update .= "|";
$update .= "";
$update .= "|";
$update .= "2";
$contents=file("../username/member.txt");
$fileName = "member.txt";
$edit_line = $_GET['record_id'];
$replace_text =$update;
// Strip carrage-returns
for($c = 0; $c < count($contents)-1; $c++)
{
$contents[$c] = str_replace( "\n", "", $contents[$c] );
}
//read file into array
//$contents = array($fileName);
//$contents = array($fileName);
// replace specified array index (user to update) with built string
$contents[$edit_line] = $replace_text;
// write array to file
if (!$fp = fopen($fileName,"w")) { die("Cannot open file"); }
// $contents = array($user_id,$password,$lastname,$firstname,$email);
// $contents= implode("|",$contents);
// $contents= chop($contents);
// $listf = fopen("member.txt", 'a+');
$count = 0;
foreach ($contents as $edit_line)
{
//fwrite($fp, $str);
if($count != $_GET['record_id']){
$str="\n".$contents[$edit_line];
fwrite($fp,$str);
}
$count++;
}
fclose($fp);
//header("Location:
}
}
?>
Navigation:
[Reply to this message]
|