Jump to content

Archived

This topic is now archived and is closed to further replies.

Gruzin

Need help

Recommended Posts

I'am trying to creat a form, I want the user to type some information and then this information to be saved in the text file. here is the code, but of course it doesn't work:(

<?php
$file = "text.txt"; //file where the information will be stored
$input_file = file($file); //opens the file and writes an array
$file_write = fopen($file, "w+"); // open file with write
$name = $_POST["name"];
fputs($file_write, print($name), "$input_file[0]"); // input the info from form
fclose($file_write);
echo "your info is saved";
?>

Share this post


Link to post
Share on other sites
[quote]doesn't work[/quote]
Doesn't help. Take a read of the link in my signiture.

Share this post


Link to post
Share on other sites
Remove print from this line:
fputs($file_write, print($name), "$input_file[0]"); // input the info from form

so its just:
fputs($file_write, $name, "$input_file[0]"); // input the info from form

Share this post


Link to post
Share on other sites
thanks, but It doesn't write anything in the text file....

Share this post


Link to post
Share on other sites
ok, I'll try some tutorials, if I can find, thanks guys

Share this post


Link to post
Share on other sites
hey guys, please help, I really need this, I've several tutorials about this, but it's not clear enough for me....
well, my problem is that when I input the text in the "name" field, it doesn't save the info in the text file. hope u can help, thanks.

here is the code of the form:
<form action="form.php" method="post" name="input" >
Name:<input type="text" name="name" />
<input type="submit" value="save" />
</form>


and here is the php code:

<?php
$file = "text.txt"; //file where the information will be stored
$input_file = file($file); //opens the file and writes an array
$file_write = fopen($file, "w+"); // open file with write
$name = $_POST["name"];
fputs($file_write, $name, "$input_file[0]"); // input the info from form
fclose($file_write);
echo "your info is saved";
?>

Share this post


Link to post
Share on other sites
Change:
[code]fputs($file_write, $name, "$input_file[0]"); // input the info from form[/code]
to:
[code]fputs($file_write, $name); // input the info from form[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.