Hope I can get some help with a quick question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jnkrois
Forum Newbie
Posts: 2
Joined: Wed Mar 05, 2008 1:30 am

Hope I can get some help with a quick question

Post by jnkrois »

I'm new to PHP, and I've been experimenting with some tutorials and such. I wanted to create a text file from an html form, so far I have been successful.
My question is:
Can I establish a variable value as the name of the txt file that I want to create?
I mean: If the html form retireves a person's name, can I use the name as the text file name that PHP can create for me?
Example

***** PLEASE USE THE

Code: Select all

OR

Code: Select all

TAGS *****[/color]

html code:

Code: Select all

<form action="form.php" method="post" name="form1">
  <label>Name
  <input type="text" name="name" id="name" />
  </label>
 
  <label>
  <input type="submit" name="Submit" id="Submit" value="Submit" />
  </label>
</form>
And then the PHP script that process the form:

Code: Select all

<?php
 
$name = "name";
 
$fp = fopen("[b]john_doe.txt"[/b], "w");
 
fwrite($fp, $your_data);
 
fclose($fp);
?>
 
Thanks in advance for taking questions?
Juan Carlos
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Hope I can get some help with a quick question

Post by Christopher »

You can get the value of name from the form in PHP from the superglobal array $_POST. The value for name will be in $_POST['name'].
(#10850)
jnkrois
Forum Newbie
Posts: 2
Joined: Wed Mar 05, 2008 1:30 am

Re: Hope I can get some help with a quick question

Post by jnkrois »

Thanks a lot, I appreciate your help, it worked just fine.

Now, what if I want to create a script that writes into an html file, but to a specific part of the file, let's says a div tag into the body tag? Is that possible?

Thanks again and sorry about adding code the wrong way before.

Juan Carlos
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Hope I can get some help with a quick question

Post by John Cartwright »

php5: file_get_contents() + str_replace() + file_put_contents()
php4: file_get_contents() + str_replace() + (fopen(), fwrite(), fclose())
Post Reply