| | |
Auto Addition Script
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Mar 2005
Posts: 9
Reputation:
Solved Threads: 0
I am trying to make a joke site..... I havent dont the rating system yet but have one previous issue to deal with and cant find it in any of my books.
I want to have a password protected admin page, addjoke.php where I can add by category like "Blonde Jokes" or "President Bush Jokes". I know how to make a form write to a different page, which is beginner php, but how do I have it be incremented 0001.php and up which will go up each time I add one, and still be placed in its specific category. This is probably simple, I dont neccessarily need an answer but if someone can point me in the right direction it would be greatly appreciated.
I want to have a password protected admin page, addjoke.php where I can add by category like "Blonde Jokes" or "President Bush Jokes". I know how to make a form write to a different page, which is beginner php, but how do I have it be incremented 0001.php and up which will go up each time I add one, and still be placed in its specific category. This is probably simple, I dont neccessarily need an answer but if someone can point me in the right direction it would be greatly appreciated.
It sounds like you plan to have each joke be it's own PHP page?
Joke #1: 0001.php
Joke #2: 0002.php
Joke #3: 0003.php
...
That will work, but considering that each joke is only a small bit of text, and that you probably have a lot of other common stuff on each page, you probably should consider storing the jokes in a database. If you don't want to deal with a database yet, you could store the jokes in simple text files that you then include within the "joke" page.
To address your question of how to build the numerically ascending filenames, first realize that you will need some mechanism to "remember" the last number in the sequence. This could be done a number of ways (no pun intended). If you store each joke in a text file named like 0001.txt, 0002.txt, 0003.txt, there are ways to retrieve the "highest" filename from the directory, break the filename apart (check out basename() or pathinfo() functions), then increase it by one and pad with zeros (check out str_pad()) to build your new filename. Probably a better method is to store your jokes in a database and simply use an autonumber id to maintain a unique index.
With either of these techniques, you would use a single page (perhaps joke.php). You'd pass a joke ID to the script, and it would return the joke. e.g. joke.php?id=145. joke.php would have code to either include the joke text file or retrieve the joke text from the database.
Joke #1: 0001.php
Joke #2: 0002.php
Joke #3: 0003.php
...
That will work, but considering that each joke is only a small bit of text, and that you probably have a lot of other common stuff on each page, you probably should consider storing the jokes in a database. If you don't want to deal with a database yet, you could store the jokes in simple text files that you then include within the "joke" page.
To address your question of how to build the numerically ascending filenames, first realize that you will need some mechanism to "remember" the last number in the sequence. This could be done a number of ways (no pun intended). If you store each joke in a text file named like 0001.txt, 0002.txt, 0003.txt, there are ways to retrieve the "highest" filename from the directory, break the filename apart (check out basename() or pathinfo() functions), then increase it by one and pad with zeros (check out str_pad()) to build your new filename. Probably a better method is to store your jokes in a database and simply use an autonumber id to maintain a unique index.
With either of these techniques, you would use a single page (perhaps joke.php). You'd pass a joke ID to the script, and it would return the joke. e.g. joke.php?id=145. joke.php would have code to either include the joke text file or retrieve the joke text from the database.
![]() |
Similar Threads
- Help w/ Malware "http://127.0.0.1:8080/ proxyconf" (Viruses, Spyware and other Nasties)
- PhpBB vs VBulletin (Growing an Online Community)
- Freelance designer (Post your Resume)
- Redhat 9.0 Server Recommendations (Linux Servers and Apache)
Other Threads in the PHP Forum
- Previous Thread: error message with sessions
- Next Thread: php.ini file not being read
| Thread Tools | Search this Thread |
# .htaccess 5.2.10 access alexa apache api array beginner broken cakephp checkbox class clean clients cms code convert cron curl database date directory display dissertation dropdown dynamic echo$_get[x]changingitintovariable... email encode error fairness file folder form forms function functions google hack href htaccess html htmlspecialchars image include indentedsubcategory ip javascript joomla legislation limit link local login mail memberships menu methods multiple multipletables mysql mysqlquery network newsletters oop open passwords paypal pdf persist php provider query radio random redirect remote script search secure server sessions simple sockets source space spam sql system table tutorial upload url user variable video voteup web youtube





