php form that will create a new webpage

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
guitars4god7
Forum Newbie
Posts: 6
Joined: Thu Oct 14, 2010 5:49 pm

php form that will create a new webpage

Post by guitars4god7 »

I am working on my first database driven site that has a form that allows users to submit essentially a quote to a database. My php file is working perfectly and submitting the required information but I would like to be able to create a new html file into a directory each time a user submits a new quote. Each html page will be based off a template so only the quote they add will change. Then there will be a webpage for each quote ie http://www.domain.com/quotes/712. I have figured out how to create the file and how to submit one line into the file but I have had no luck placing a couple hundred lines of html into it. Any help would be greatly appreciated!! Chance

Code: Select all

$q = "select MAX(id) from likes";
$result = mysql_query($q);
$data = mysql_fetch_array($result);
$idnumber1 = $data[0];


$myFile = "quotes/".$idnumber1.".html";
$fh = fopen($myFile, 'w') or die("can't open file");
$str = "This is a test";
fwrite($fh, $str);
fclose($fh);
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: php form that will create a new webpage

Post by requinix »

No offense but you're doing it wrong.

All based on a template, right? Something you could easily create with PHP if you had the information, right?
Use URL rewriting to turn /quotes/123 into (for example) /quotes.php?id=123. Then write PHP to fill in the template.
guitars4god7
Forum Newbie
Posts: 6
Joined: Thu Oct 14, 2010 5:49 pm

Re: php form that will create a new webpage

Post by guitars4god7 »

I don't take offense at all and figured I was doing it wrong anyways so I could surely use the advice.

I did some quick searches for url rewriting with php and couldn't find anything helpful. Would you be able to give a link or something to an example of how to do it? If I have something to go by I can surely figure out how to implement it. Thanks for your help
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: php form that will create a new webpage

Post by John Cartwright »

Search under mod rewrite, which has a ton of information out there.
guitars4god7
Forum Newbie
Posts: 6
Joined: Thu Oct 14, 2010 5:49 pm

Re: php form that will create a new webpage

Post by guitars4god7 »

Ok so I figure a simple .htaccess file like this should do the trick but its still not working... what am I missing? Also what would be the php variable to use to do a mysql query with to find the appropriate quote for the page they requested?

RewriteEngine on
RewriteRule /quotes/([0-9]+) /quotes/quotes.php?id=$1
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: php form that will create a new webpage

Post by requinix »

mod_rewrite can be weird, at times. Try

Code: Select all

RewriteEngine on
RewriteBase /
RewriteRule quotes/([0-9]+) quotes/quotes.php?id=$1 [L]
(The [L] means that's the last rule to execute. Most people assume it will be anyways and write rules accordingly.)
guitars4god7
Forum Newbie
Posts: 6
Joined: Thu Oct 14, 2010 5:49 pm

Re: php form that will create a new webpage

Post by guitars4god7 »

Not exactly right but it got me on the right track so atleast I am making progress. This is the code that worked:

Code: Select all

RewriteEngine on
RewriteRule ^quotes/([0-9]+)$ quotes/quotes.php?id=$1 [L]
Now whenever someone types http://www.domain.com/quotes/5 it gives that template which is perfect! I just finished editing the php in the template to display the appropriate quote depending on what id number is entered. Thanks for your help everyone. Problem solved :D
Post Reply