Using PHP to automatically create .php files?

{NcsO}ReichstaG

[H]ard|Gawd
Joined
Aug 13, 2004
Messages
1,768
Hey
So I am building a website that runs almost entirely of a MySQL database. I created submission form in which the person fills out certain fields such as, Article Name, and the actual Article Body. There are like 4 columns in the database. (Article ID, Article Name, Article Body, Article_Date Posted) Anyway, this information is submitted into the MySQL DB (Each new article is given a new ID, and assigned the date posted). Then on the main page, I have a php script that reads the values. It displays the article name and the date created and the link to the article, such as, "<a href="/articles/$article_name/">. However, the problem is this: Where do I actually post the real article? Basically my thought was to have a script that autmatically creates .php file in the htdocs directory everytime a new article is made. The .php created should include basic php information so that it can read the connect to the MySQL DB.
Basically I want every time a new article is submitted, for a .php file to be created with default information in it like this:
Code:
mysql_select_db("ArticleArchive",$SQL) or die (mysql_error());
$Query = "SELECT * FROM articles
          ORDER BY ArticlesT_ID DESC LIMIT 2
		  ";
$Enter = mysql_query($Query) or die(mysql_error());
while($rows = mysql_fetch_array($Enter))
{
...............so on..........
}
and named after the name of the article.....
So is this possible?
-Thanks
 
You could create a file per entry, but that's an inefficient solution.

You want to create an article template page that is generic across all (or a significant subset of) your entries. Then you'll link to .../article.php?article_id=something, and article.php can then reference $_GET['article_id'], look up the article from SQL, and display it. One file fits all.

If you want to make files, though, look in the File section of the PHP manual at php.net.
 
mod_rewrite is a means of structuring your URLs (say, directing ../articlename to ../article.php?name=articlename) but it's not a solution to your original question.
 
Are there any good tutorials on mod_rewrite..? It seems like an interesting concept that I would like to learn, except I can't find any really good tutorials on it on goooooogle

-Also thanks for the more efficent solution lomn75
I passed the ID information through URL variables. Then I just filtered it by: Where Articles_ID=ID_of_article_clicked_on.
 
Another thing to keep in mind is that for a page where there's enough page views to tax the DB server, it might be more effective to write the complete page or parts of it (after grabbing things from the DB) to a static file whenever it's updated.
 
Also, does can anyone give me guidance to solve this problem:
Whenever I increase the text size in my browser, the text size goes out of the proportion of the frame. Basically the text size view in my browser increaseses, but the layout does not increase at all............
 
Without seeing yoru webpage's source code, I'm going to assume that your layout has predefined widths for any table or div you've made.. Take a look in your source code and see if you have "width = 800px" or something that predefines the size of divs/tables.
 
Or set it to a number of em's and it should scale properly. Just off the top of my head, of course.

 
One more question:
I have a .php file that process DataBase submissions. So..the admins fill out a form with a sn/pw and then click submit and that info is submitted. Any1 however can view the form, however, they can submit because of the sn/pw requirement. However, if after viewing the form, they go to the dbsubmission.php file, they see this:
Code:
Notice: Undefined index: ArticleType in C:\Program Files\Apache Group\Apache2\htdocs\DBinterface.php on line 16

Notice: Undefined index: NoA in C:\Program Files\Apache Group\Apache2\htdocs\DBinterface.php on line 17

Notice: Undefined index: ArticleSubmission in C:\Program Files\Apache Group\Apache2\htdocs\DBinterface.php on line 18

Notice: Undefined index: title in C:\Program Files\Apache Group\Apache2\htdocs\DBinterface.php on line 19

Notice: Undefined index: Annoucement in C:\Program Files\Apache Group\Apache2\htdocs\DBinterface.php on line 20

Notice: Undefined index: Description in C:\Program Files\Apache Group\Apache2\htdocs\DBinterface.php on line 21

Notice: Undefined index: PW in C:\Program Files\Apache Group\Apache2\htdocs\DBinterface.php on line 23

Notice: Undefined index: SN in C:\Program Files\Apache Group\Apache2\htdocs\DBinterface.php on line 24
(Even though I tried to prevent this by using sessions,however, if they go to the fill out form first, they still see the errors)
Are the errors exposing site vulnerabilities?
 
I don't quite understand what you're saying, but you can use error_reporting(0) to disable that.
 
Back
Top