CBI Web Posted October 30, 2009 Share Posted October 30, 2009 Hi everyone, first time poster here so be gentle. I'm not new to PHP but am new to actually writing scripts and working it with MySQL from scratch, and so far have done well, but I'm stuck on one thing. Long story short, after entering information into a form and submitting, I want the resulting page to be a pure HTML page, not a script that pulls from the database and prints to screen. How do I do that? Thanks for the help. Quote Link to comment https://forums.phpfreaks.com/topic/179682-solved-how-do-i-generate-a-static-html-page-with-php/ Share on other sites More sharing options...
trq Posted October 30, 2009 Share Posted October 30, 2009 I'm not new to PHP but am new to actually writing scripts Then you are new to php. Simply make your forms action point to whatever file you need. Of course, if its just a html page it won't be able to process for your form (so I don't see much point), but, you asked. Quote Link to comment https://forums.phpfreaks.com/topic/179682-solved-how-do-i-generate-a-static-html-page-with-php/#findComment-948057 Share on other sites More sharing options...
taquitosensei Posted October 30, 2009 Share Posted October 30, 2009 the resulting page is HTML well it could be html and javascript. PHP processes on the server and then spits out the HTML that the browser then displays. Two separate things. Server side and client side. Server side - PHP Client Side - HTML / Javascript Quote Link to comment https://forums.phpfreaks.com/topic/179682-solved-how-do-i-generate-a-static-html-page-with-php/#findComment-948065 Share on other sites More sharing options...
Goldeneye Posted October 30, 2009 Share Posted October 30, 2009 So you just want to output static-data to the client? That sounds like the echo() construct will do you good, then. http://php.net/echo Quote Link to comment https://forums.phpfreaks.com/topic/179682-solved-how-do-i-generate-a-static-html-page-with-php/#findComment-948069 Share on other sites More sharing options...
CBI Web Posted October 30, 2009 Author Share Posted October 30, 2009 hmmm... okay, then something else is wrong. What I'm doing is creating pages that have slightly different information on them, depending on what a person submits in the form. Each page can be viewed at a unique URL for each person. The one problem I'm having is every time I go to the URL of any one of the pages that are generated, it doesn't display the content I expect to see. In fact it's basically displaying the information from the most recent submitter. Any ideas? I'm stumped after trying to work it out for two days. Quote Link to comment https://forums.phpfreaks.com/topic/179682-solved-how-do-i-generate-a-static-html-page-with-php/#findComment-948085 Share on other sites More sharing options...
trq Posted October 30, 2009 Share Posted October 30, 2009 You need to post some relevant code. Quote Link to comment https://forums.phpfreaks.com/topic/179682-solved-how-do-i-generate-a-static-html-page-with-php/#findComment-948089 Share on other sites More sharing options...
CBI Web Posted October 30, 2009 Author Share Posted October 30, 2009 Here's a sample of the script for the page in question: <?php include ("../db_connect.inc"); if (!$conn) { echo "Unable to connect to DB: " . mysql_error(); exit; } if (!mysql_select_db($dbname)) { echo "Unable to select mydbname: " . mysql_error(); exit; } $result = mysql_query("SELECT * FROM thistable"); while ($row = mysql_fetch_assoc($result)) { $today = $row["today_date"]; $month = $row["month"]; $year = $row["year"]; $first_name = $row["first_name"]; $last_name = $row["last_name"]; $email = $row["email"]; } mysql_free_result($result); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Lorem Ipsum</title> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <link rel="stylesheet" type="text/css" href="../styles/main.css" /> </head> <body> <p>Today is the <?php echo $today ?><?php echo date('S'); ?> day of <?php echo $month ?>, <?php echo $year ?></p> <p>My first name is <?php echo $first_name ?></p> <p>My last name is <?php echo $last_name ?></p> <p>My email address is <?php echo $email ?></p> </body> </html> This creates a page with the relevant information submitted by a person. Each page has it's own URL in this format: www.mysite.com/john/index.php www.mysite.com/dave/index.php www.mysite.com/carol/index.php ...and so on So everyone who submits their info can view the resulting page anytime they want, using their own URL. and I have the whole system working exactly as I want, except that each unique page is showing the data from the most recent submitter. Quote Link to comment https://forums.phpfreaks.com/topic/179682-solved-how-do-i-generate-a-static-html-page-with-php/#findComment-948109 Share on other sites More sharing options...
trq Posted October 30, 2009 Share Posted October 30, 2009 You need to have a clause within your query that will select data specific to a certain user. eg; <?php <?php include ("../db_connect.inc"); if (!$conn) { echo "Unable to connect to DB: " . mysql_error(); exit; } if (!mysql_select_db($dbname)) { echo "Unable to select mydbname: " . mysql_error(); exit; } if (isset($_GET['user'])) { $user = mysql_real_escape_string($_GET['user']); $result = mysql_query("SELECT * FROM thistable WHERE first_name = '$user'"); // rest of code } You can then get data on Dave by accessing this page via www.mysite.com/index.php?user=dave You would then use mod_rewrite to rewrite your urls as you have above. No need to make a separate file for each user. Quote Link to comment https://forums.phpfreaks.com/topic/179682-solved-how-do-i-generate-a-static-html-page-with-php/#findComment-948111 Share on other sites More sharing options...
CBI Web Posted October 30, 2009 Author Share Posted October 30, 2009 Aha! Yes, that clause is what I need. I do already make a separate file for each user, so that's no problem. It was just that one issue tripping me up. Thanks! edit: oops, misread your statement about the separate file. Got it now.. cool. Quote Link to comment https://forums.phpfreaks.com/topic/179682-solved-how-do-i-generate-a-static-html-page-with-php/#findComment-948114 Share on other sites More sharing options...
trq Posted October 30, 2009 Share Posted October 30, 2009 I do already make a separate file for each user, so that's no problem There really is no need to do that and it is in fact a ridiculous method to use for such a problem. Quote Link to comment https://forums.phpfreaks.com/topic/179682-solved-how-do-i-generate-a-static-html-page-with-php/#findComment-948118 Share on other sites More sharing options...
CBI Web Posted October 30, 2009 Author Share Posted October 30, 2009 Yes, I edited my post after re-reading your previous one. Sorry if I've done something ridiculous, but I'm learning this stuff as I go, and Googling doesn't always give me what I need, so I wing it. I have a lot to learn. Quote Link to comment https://forums.phpfreaks.com/topic/179682-solved-how-do-i-generate-a-static-html-page-with-php/#findComment-948122 Share on other sites More sharing options...
trq Posted October 30, 2009 Share Posted October 30, 2009 but I'm learning this stuff as I go Probably not the best way of doing it because without an overall picture of what can be done you will do things the long/hard way. Quote Link to comment https://forums.phpfreaks.com/topic/179682-solved-how-do-i-generate-a-static-html-page-with-php/#findComment-948124 Share on other sites More sharing options...
CBI Web Posted October 30, 2009 Author Share Posted October 30, 2009 I'm finding it hard to find what I need to know to make it less difficult. I've learned quite a bit about MySQL and PHP via books and the Internet, but putting the two together is tripping me up here & there. Some things seem to be elusive. But hey, I've only been at it for a month or so. Maybe phpfreaks will be a good place to pick up some much needed knowledge? Quote Link to comment https://forums.phpfreaks.com/topic/179682-solved-how-do-i-generate-a-static-html-page-with-php/#findComment-948128 Share on other sites More sharing options...
trq Posted October 31, 2009 Share Posted October 31, 2009 Maybe phpfreaks will be a good place to pick up some much needed knowledge? Yeah, this site is great when you get stuck but reading entire books is probably the best way to go because they move in a progression and a good one should cover pretty much the basics of everything. Quote Link to comment https://forums.phpfreaks.com/topic/179682-solved-how-do-i-generate-a-static-html-page-with-php/#findComment-948129 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.