Jump to content

[SOLVED] How do I generate a static HTML page with PHP?


CBI Web

Recommended Posts

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. :)

Link to comment
Share on other sites

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. ;)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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. :)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.