By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,261 Members | 1,688 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,261 IT Pros & Developers. It's quick & easy.

Writing Form contents back to file

pradeepjain
100+
P: 563
[HTML]<html>
<head>
</head>
<body>
<?php

$filehandle = fopen("welcome.txt","r");

if(filesize("welcome.txt")=='0')
{
echo "file empty";
}
else
{
$line=true;

echo '<form method=post action=action.php>';

while($filehandle && $line)

{

$line = fgets($filehandle);

if (!empty($line))

{

$str = explode(':', $line);

echo $str[0] . ': <input type="text" name="'.$str[0].'" value="'.$str[1].'"><br />';

}

}



echo '<input type=submit value= submit>';

echo '</form>';
}
?>

</body>
</html>
[/HTML]


see the code tht i hve given works perfectly...i am reading the contents of the file tht contents lke
name:pradeep
place:blore

this is jst an example ..it might contain anything...i hve jst been said tht it contains 2 string seperated by ":"...and there are many lines lke this...
i hve done the reading part ..
now i hve stuck up in writing part...lke wht shld i take for name in $_POST["name"]..bcos i wll be not knowing whts in the file.
Aug 4 '07 #1
Share this Question
Share on Google+
3 Replies


pbmods
Expert 5K+
P: 5,821
Heya, Pradeep.

What do you want your code to do? Give an example.
What is your code doing that you don't want it to do? Give an example.
What is your code *not* doing that it is supposed to? Give an example.
Aug 4 '07 #2

pradeepjain
100+
P: 563
Heya, Pradeep.

What do you want your code to do? Give an example.
What is your code doing that you don't want it to do? Give an example.
What is your code *not* doing that it is supposed to? Give an example.

het this code is working correctly...as u can see i am displaying the file contents in a form...
there i am giving a submit button so as to submit the dited content from the form and the write it back to the file...i need to write the the php code for writing the form contents back to the file....

hope i am clear
Aug 5 '07 #3

pbmods
Expert 5K+
P: 5,821
Heya, Pradeep.

Have a look at file_put_contents().
Aug 5 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.