Hi all,
What I am trying to do is
On "Page 1", user fills a form, and when he clicks on "Submit",
a new page, say "Page 2" should get automatically created (in the same folder as index.php) in such a way that name of the page is say first_name.php (what the user filled on page 1) and it should display the contents of what he filled in on the first page.
Something like showed in the figure.
http://i54.tinypic.com/j768wj.jpg
Please help guys!
Thanks and Regards.

Recommended Answers

All 9 Replies

Member Avatar for Lioshenka

Well, on the first page you will ned to have some code like this:

<form method="post" action="../yoursecondpage.php">
                Username:<input type="text" name="username" size="15"/>
                  <input type="submit" name="login" value="Log In" />
</form>

This basically allows the user to type their name in ans post it to the second page.

Now, the second page will need to have some code like this:

$fh = fopen($_POST['username'], 'w');
fwrite($fh, stripslashes($_POST['username']));
fclose($fh);

populate it with the text.

I think that's pretty much it.

PS Mind you, all the second page does is creates a new file and puts user's text into it. You can add an echo statement to display the text (or include, or redirect) - but the code above doesn't actually show anything to the user at the moment.

It depends on some browser. But you can try this.

<form action='page2.php' method='post' target='_blank'>

All version of IE supports the target='_blank' tags.

Why would you want to create a new file in the folder just for that? You could potentially be inundated with a huge amount of files in the folder if many people or bots filled and submitted the form. I am not sure what you are attempting to do but I bet there is a better way to achieve your goal.

You should not create a page for each person, in my opinion.
You can use a custom page to simply echo the contents of the form. If its a profile page you are creating, you can store user details in a database.

Vinayak

Thanks for your help guys. But as pixelsoul and Vinayak said, I need to create a new file and the filename needs to be user-desired. Like I mentioned in the figure, http://i54.tinypic.com/j768wj.jpg once the user John hits Submit, a new page john.php gets created.
So basically, I need a form-action based code to create a new php page.
Thanks again..

Member Avatar for Lioshenka

That's what my script does, doesn't it? It creates a file, naming it exactly as what user has typed in and also populates it with the same data.

@Lioshenka,
Thanks for the help buddy. /but what your code does is creates a file. I want something to create a permalink. Like in the figure, the page john.php should be for permanent.
If your code does that, then I'm sorry, maybe I'm not following your steps properly.

Member Avatar for Lioshenka

Yes, that's what my code does. You have two pages - one is with the form, and another one is just a script which creates john.php. So this is basically what happens:

- John fills in the form on firstpage.php and clicks Submit
- firstpage.php sends John's name (what he typed) to the secondpage.php
- secondpage.php creates file called john.php and saves it in the same folder as firstpage.php and secondpage.php

If Mary then visits the page, same thing happens and a 4th file called mary.php is created in the same directory. Hope this helps :)

PS you said you want the secondpage.php to display John's name too - this can be achieved by adding a simple

echo "$_POST['login'];

line in the secondpage.php

Let me know if you are still having troubles - I can try and actually write both php files for you if I can :)

@Lioshenka
Oh, sorry. I did not go that way. I will try it.
Thanks a lot for your help. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.