URGENT: Simple PHP script that creates a new page upon user text submission.
Hello,
I will try and explain this the best I can.
Basically what I am looking for is simple PHP/HTML code that basically takes the text inserted into a text box on the homepage and creates a new page and labels it e.g http://example.com/?id=1232, and the new page http://example.com/?id=1232 will contain the text submitted from the homepage.
To run over it one more time, I would like to visit the homepage and there be a text box, I insert some text into the text box, click submit, and then it takes me to a new page It's just created with the text I just submitted on it.
I would be massively grateful if anyone could help.
1) Can "anyone" do it, or does it require a login or password?
2) What about allowing HTML or URL links? Yes or No?
3) Instant update without any admin verification or auditing?
4) What about editing it, if they discover a mistake?
5) How long is the file retained? Does it ever get overwritten?
6) What about references to photos or images?
7) What about text size formatting? Maybe you're thinking of a RTF type of form?
8) How about security as in captcha, or something to thwart spammers?
I have more ... but you can probably tell that your original post has "not enough info".
1. Yes, anyone can do it.
2. I'm unsure on what you mean.
3. Yes, Instant update, does not need admin verification.
4. No, they cannot edit it.
5. It will be retained forever, It will never be overwritten.
6. No, will just be text and will require no reference the the person that submitted it.
7. I can sort the text sizing ect, I'm just looking for a simple text form that submits the data inside.
8. No, a captcha wouldn't be necessary.
Sorry again for not enough information, please feel free to ask more..
This is a little different than what you need, but it's basically there.
In this example, the text files already exist. It can edit existing text files.
You would need to create them AND save changes (which would be the difference).
Perhaps you would like to do both ... create and/or edit them?
Here's my shot at it ...
I name this file "edit.php". If you give it a different name, you must adjust the script.
// Not sure how you will name your text files,
// but in this example, I name them p1.db, p2.db etc.
// You can use .txt ... I just like using something like .db
$url = "p".$p.".db";
// Make sure file exists ...
if (file_exists($url)) {
// do nothing
} else {
// You can create the file here (since it doesn't exist).
// In my example, I kick them out and redirect back to index ...
$page=0;
header ("location: index.php");
}
// Where to return to at the top of the editor page <- Return ...
$return="index.php?p=$p";
Heres my shot at what I think it is your looking for.
A user can enter text into the textbox and it will create a file with its own unique id number (which auto starts itself if there are no files in the folder) you will need a folder to store the files in as it will only work like this and it needs to be set to 777 Chmod to allow the code to write to the folder.
If you goto http://example.com/?id=1 and there is a file with an id of 1 it will redirect to that file otherwise it will take the id query off the url.
__________________
Official BinPress hand picked coder.
For anyone worried about SQL injection go have a look at my small yet powerful script here.
Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
I am 1 of 65,608 people to get a Pebble Watch :P
Thanks for the useful posts, but I would need the data that is entered into the text field, to be inserted into a MySQL database.. so effectively what is happening is you visit the homepage, you type some text into the text box, the text gets inserted into a field in a database called "content" for example, and then that content can be accessed by visiting http://example.com/view.php?id=1
So what is it your trying to do is it an id number for each link for example.
id=21 == hello world
id=2345 == you whats up
etc?
__________________
Official BinPress hand picked coder.
For anyone worried about SQL injection go have a look at my small yet powerful script here.
Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
I am 1 of 65,608 people to get a Pebble Watch :P
1. Text is entered into a text box.
2. That text is inserted into the database.
3. That text is also asigned with an ID, so it can be accessed at http://example.com/link.php?id=1
4. When you visit http://example.com/link.php?id=1 the text that you entered in the first place will be visible on the page..
Just use a sql query for this and as i dont know your database table name or columns ill put my own in and you edit it for yourself.
PHP Code:
$id = mysql_escape_real_string($_GET['id']); $sql = mysql_query("SELECT * FROM links WHERE id = '{$id}'") or die(mysql_error()); if(mysql_num_rows($sql)) { while($link = mysql_fetch_array($sql)) { print $link['content']; } }
Which this should display the content (e.g. the text that was entered into the textbox) which is assigned to the id in $_GET['id'].
And are you asking for a script where after you submit the text you get taken to that page to if you have 5 links into the database and you submit a new link you get taken to /link.php?id=6 ???
__________________
Official BinPress hand picked coder.
For anyone worried about SQL injection go have a look at my small yet powerful script here.
Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
I am 1 of 65,608 people to get a Pebble Watch :P
__________________
Official BinPress hand picked coder.
For anyone worried about SQL injection go have a look at my small yet powerful script here.
Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
I am 1 of 65,608 people to get a Pebble Watch :P
Well it would have been better as the problem would have been sorted faster but people never know how to explain things fully and as the post go on more information comes with them.
__________________
Official BinPress hand picked coder.
For anyone worried about SQL injection go have a look at my small yet powerful script here.
Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
I am 1 of 65,608 people to get a Pebble Watch :P
Thanks for all your code, I just need to put the relevant bits together now. I need the HTML text box code that submit the text from the box into the database, and the PHP code that reads the number after ".com/?id=" and then finds the ID number in the database, and then shows it on the same page..
Your help would be greatly appreciated.
Thanks..
Last edited by JonathanFenny; 06-01-2010 at 02:27 AM..