Snubby Posted October 17, 2006 Share Posted October 17, 2006 I'm not sure if I am a complete noob, or if this isn't PHP, but how can I permanently change a page without having to moderate the HTML from a form.For eg. I want to program a news system for the relaunch of my site, so I would have a hidden URL that I could have a form on, like, 'Title, Date, Information' and then when I submit it the page would from that point on include that information on the news page.I know how to submit things and use get and post, and I know how to open files, but I can't figure out how to do this from that knowledge. Help, please! Link to comment Share on other sites More sharing options...
justsomeguy Posted October 17, 2006 Share Posted October 17, 2006 You want a page with a form on it, including those three fields, and when you fill them out and hit submit the news page will display the information you put in the fields. Am I understanding you?Also, have you used databases yet, or only files? Link to comment Share on other sites More sharing options...
whatabrother Posted October 17, 2006 Share Posted October 17, 2006 I'm not sure if I am a complete noob, or if this isn't PHP, but how can I permanently change a page without having to moderate the HTML from a form.For eg. I want to program a news system for the relaunch of my site, so I would have a hidden URL that I could have a form on, like, 'Title, Date, Information' and then when I submit it the page would from that point on include that information on the news page.I know how to submit things and use get and post, and I know how to open files, but I can't figure out how to do this from that knowledge. Help, please!All the information that you need is here at w3schools. The approach that I have taken to this in the past has been to use the require() function to call all the information out of a file in to the location that you want it in the text. Then to post the information in to that file, you will need to use some filesystem functions. A page that posts the text could look something like this:<?php if (!isset($_GET )) { if (file_exists("maintext.txt")) { $content = file_get_contents("maintext.txt"); } echo 'Please Insert text:<br><form action="thispage.php?page=yes" method="post"><textarea height="400" width="400" name="text">' . $content . '</textarea><br /><input type="submit" value="submit your text" /></form>'; } if (isset($_GET )) { if (!isset($_POST[text])) { echo "You must insert some text "; exit; } file_put_contents("maintext.txt",$_POST[text]); }?> Then to display the text: <html><body>This is the text that was posted:<br> <?php require "maintext.txt"; ?></body></html> Link to comment Share on other sites More sharing options...
Snubby Posted October 17, 2006 Author Share Posted October 17, 2006 So, I'd have to make a form modify a .txt file, and then 'require' that file? I'll try it, thanks To justsomeguy, I've only worked with files, not databases. Link to comment Share on other sites More sharing options...
whatabrother Posted October 17, 2006 Share Posted October 17, 2006 So, I'd have to make a form modify a .txt file, and then 'require' that file? I'll try it, thanks To justsomeguy, I've only worked with files, not databases. Yeah, that should work. About databases, that would be another way to do it, and i've done it that way before, but I don't know of a way to store more than 255 characters in a database, so for me it isn't the best way. Link to comment Share on other sites More sharing options...
justsomeguy Posted October 18, 2006 Share Posted October 18, 2006 The text data type will store up to 64KB of text, mediumtext will store up to 16.7MB, and longtext will store up to 4.3GB of text. The tinytext, char and varchar types will only hold up to 255 bytes. tinyblob, blob, mediumblob, and longblob are like text, except for binary data.http://mysql.org/doc/refman/4.1/en/storage-requirements.html Link to comment Share on other sites More sharing options...
whatabrother Posted October 18, 2006 Share Posted October 18, 2006 The text data type will store up to 64KB of text, mediumtext will store up to 16.7MB, and longtext will store up to 4.3GB of text. The tinytext, char and varchar types will only hold up to 255 bytes. tinyblob, blob, mediumblob, and longblob are like text, except for binary data.http://mysql.org/doc/refman/4.1/en/storage-requirements.html Well I guess you learn something new everyday. Thanks for that. Link to comment Share on other sites More sharing options...
jhecht Posted October 18, 2006 Share Posted October 18, 2006 in reply to the characters not being able to store more than 255 bytes in a database, you can just use text and alter the table to a FULLTEXT (means it just stores what you put in it pretty much, just in case you have some REALLLY LOOOOOONG posts) Link to comment Share on other sites More sharing options...
Snubby Posted October 18, 2006 Author Share Posted October 18, 2006 for some reason file_put_contents () function doesn't work for me, it says it doesn't recognize the function. How do I add/write information to a file? Link to comment Share on other sites More sharing options...
whatabrother Posted October 18, 2006 Share Posted October 18, 2006 for some reason file_put_contents () function doesn't work for me, it says it doesn't recognize the function. How do I add/write information to a file?It is probably because your host doesn't support it, possibly for security reasons (I really don't know why for sure). Usually you would just use the ftp functions, but I think, for you, it would just be easier to use a database. It is really simple, and sooner or later you are going to need it anyways. W3schools has a good tutorial for it here. Also, it may be a good idea for you to learn something about content filtering (assuming that you havn't already), as you will probably want to do this. preg_replace() is a good function to filter with, and the PHP manual explains it pretty well here. To use that you will also probably need to a little bit about regular expressions. If that isn't helpful to you, than hopefully it can be for somebody else. Link to comment Share on other sites More sharing options...
justsomeguy Posted October 18, 2006 Share Posted October 18, 2006 file_put_contents was added in PHP 5, a lot of hosts have not upgraded from PHP 4 yet. In the olden days, before file_put_contents, everyone just used fwrite. You can find examples here:http://www.php.net/manual/en/function.fwrite.php Link to comment Share on other sites More sharing options...
whatabrother Posted October 18, 2006 Share Posted October 18, 2006 file_put_contents was added in PHP 5, a lot of hosts have not upgraded from PHP 4 yet. In the olden days, before file_put_contents, everyone just used fwrite. You can find examples here:http://www.php.net/manual/en/function.fwrite.php I bought some hosting a while back that didn't allow about 50% of the filesystem functions. I just assumed that this was the case. Still, I think the universal solution to his problem is to use a database. Link to comment Share on other sites More sharing options...
Snubby Posted October 18, 2006 Author Share Posted October 18, 2006 Cool, thanks for all the help guys. I'm going to learn about databases. Link to comment Share on other sites More sharing options...
justsomeguy Posted October 18, 2006 Share Posted October 18, 2006 Databases are generally more efficient, and I think easier, then using files. With files you can also run into permissions issues. Hosts can deny access to any PHP functions they choose, I just haven't seen a lot of hosts actually do that. I'm sure some free hosts do, but I've never used a free host. My hosts usually set up a virtual server, so I can't access other user's files anyway. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now