Jump to content

[SOLVED] php to create html help? newbie here!


DeeDee2010

Recommended Posts

Hello, the problem is that I don't know exactly what to look for, that's why I write in a forum, asking for help.

Basically, I have a site (static html), and what I would like to do with php help is the following. Every time I need to create a new "transaction number info page" html file for a customer (e.g. FS4234FGS.html), I do it offline with the help of a HTML editor, I replace the info (name, address, information about product, etc), save it as a new transaction number file (eg SSFFD242.html) and reupload it on the site, and give the customer the name of this file, so he can access it on my site, by entering it in a field, which checks if the file is available and redirect the customer to it.

 

I would like if possible to cut the time spent of doing this and to be able to create this kind of new files directly on my website, to be like accessing a http://www.mysite.com/neworder.php kind of a file which after filling some forms would create a new file with a given name, keeping the template of the html file, and replacing only the data that needs to be replaced (like $fname, $lname etc).

 

I guess you kind of understand my wish, can that be possibly done with php? If you don't have the time to explain, can you at least point me in to right direction, what EXACTLY kind of script do I need to look for?

 

Thank you very very much. :oops:

Link to comment
Share on other sites

Absolutely no need to create files for this! Simply use a database where you store records containing ID, Name, Address, information about product, etc. Then have the user navigate to http://www.mysite.com/neworder.php?id=SSFFD242

 

Then that page will get the record from the database for that ID and then display the "template" with that record's data.

Link to comment
Share on other sites

Hi

 

Should be fairly easy to do.

 

Essentially you would have one page to enter the details onto. Store these details onto a table and with a random key (ie, probably the same randomly generated id as your file name).

 

Then another page would be something like "displaydetails.php?id=SSFFD242" . This would then go off, bring back the details from the table for id SSFFD242, and put those details into the page it returns.

 

It would be quite simple to do. Not sure how much detail help you need.

 

Starting point would be be save an existing file (say SSFFD242.html) as displaydetails.php. In there at the start put <?php, then some code to retrieve the details then a ?> (these tags signal the start and end of php, the rest is just put straight out as html).  Where the detail is in the html put (for example) <?php echo $name; ?>, where $name is a variable which you have set with the value of name you have pulled back from the table.

 

All the best

 

Keith

Link to comment
Share on other sites

Hi

 

It can be done without a database if needs be (although most of the time if you have access to php then you have access to a MySQL database). Just same the data to a file, and bring it back from that file when required. Each line of the file could start with your generated key name then a "," then the first field of data. Read each line "explode" it and then if it is the one you want output it. You just add a new record to the end each time you add a "document".

 

All the best

 

Keith

Link to comment
Share on other sites

Ok, to be a little more specific. A helpful person (susrisha) gave me some hints, so I present you a code, and some requests to modify it if possible:

 

 

My html to insert the data to be modified might look like this:

 

 <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="myscript.php" method="post">
<table>
<tr>
<td>
Detail1
</td>
<td>
<input type="text" name="Detail1"/>
</td>
</tr>
<tr>
<td>
Detail2
</td>
<td>
<input type="text" name="Detail2"/>
</td>
</tr>
<tr>
<td>
Detail3
</td>
<td>
<input type="text" name="Detail3"/>
</td>
</tr>
<tr>
<td>
Detail4
</td>
<td>
<input type="text" name="Detail4"/>
</td>
</tr>
<tr>
<td>
Detail5
</td>
<td>
<input type="text" name="Detail5"/>
</td>
</tr><input value="Go" name="submit" type="submit" style="background: #FF6600; color: white; font: 10pt bold Verdana">
</table>
  
</form>
  
</body>
</html>

 

 

 

Then myscript.php might look like this:

 

 

  
<?php
$upload_dir="./transaction_numbers/"; //change this to the directory where you want to put the files.
  
  
/*function generate_random_string
   generates a random string of given length and for a given seed
*/
function generate_random_string($length,$seed=123)
{
$randPWD1 = '';
srand((double)microtime()*1000000);
for($i=0;$i<$length;$i++)
{
     $n = rand(48,120);
     while (($n >= 58 && $n <= 64) || ($n >= 91 && $n <= 96))
     {
         $n = rand(48,120);
     }
     $randPWD1 .= chr($n);
}
  
$randPWD1 = $randPWD1.time().$seed;
$randPWD = strtolower($randPWD1);
  
$randPWD = md5($randPWD1);
$randPWD = substr($randPWD,0,$length);
return $randPWD;
} //end of function generate_random_strin
  
$file_name=generate_random_string(8,122);
$file_path =$upload_dir.$file_name.'.html';
//get all the posted values here
  
$detail1=$_POST['Detail1'];
$detail2=$_POST['Detail2'];
$detail3=$_POST['Detail3'];
$detail4=$_POST['Detail4'];
$detail5=$_POST['Detail5'];
//$detail1=$_POST['Detail1'];
  
//open the file in write mode
$fh = fopen($file_path,"w");
//write all the variable details into the file
fwrite($fh,$detail1 );
fwrite($fh,$detail2 );
fwrite($fh,$detail3 );
fwrite($fh,$detail4 );
fwrite($fh,$detail5 );
fclose($fh);
  
//show the page details to the customer
echo "Your information has been stored as $file_name";
echo "<a href=\"$file_path\">Click Here to see</a>";
?>

 

 

 

 

1. I would like the newly created html file to begin with : ZG + numbers + letters + the first 3 letters in the name of "last name" of the customer - that I fill in in the first html file. (12 character transaction number, only uppercase)

2. Can you tell me how can I insert my own html template in the output? Because now, it only writes a new html file, containing only the data inserted, without any other information (my template).

 

Can you help me please? Thanks God, there are forums out there, I simply couldn't know what to look for!

Link to comment
Share on other sites

Hi

 

Those scripts will give you the basics.

 

It is randomly generating a file name. You could alter the routine to give you a file name in the format you want, but I would need a few more details (eg, how many numbers and letters).

 

You could have a variable set up as (for a rough example), so replace:-

 

//open the file in write mode
$fh = fopen($file_path,"w");
//write all the variable details into the file
fwrite($fh,$detail1 );
fwrite($fh,$detail2 );
fwrite($fh,$detail3 );
fwrite($fh,$detail4 );
fwrite($fh,$detail5 );
fclose($fh);

 

//open the file in write mode
$fh = fopen($file_path,"w");
//write all the variable details into the file
$outputdata = "<html><head></head><body>Various bits of stuff $detail1 some more stuff $detail2</body></html>";
fwrite($fh,$outputdata );
fclose($fh);

 

You can (I hope) see where you would put your html and the $detail1, etc, would be the bits that change taken from the form.

 

Not that while this would work it is totally insecure, so make sure nobody has easy access to it.

 

All the best

 

Keith

 

 

 

Link to comment
Share on other sites

Hi

 

Those scripts will give you the basics.

 

It is randomly generating a file name. You could alter the routine to give you a file name in the format you want, but I would need a few more details (eg, how many numbers and letters).

 

You could have a variable set up as (for a rough example), so replace:-

 

//open the file in write mode
$fh = fopen($file_path,"w");
//write all the variable details into the file
fwrite($fh,$detail1 );
fwrite($fh,$detail2 );
fwrite($fh,$detail3 );
fwrite($fh,$detail4 );
fwrite($fh,$detail5 );
fclose($fh);

 

//open the file in write mode
$fh = fopen($file_path,"w");
//write all the variable details into the file
$outputdata = "<html><head></head><body>Various bits of stuff $detail1 some more stuff $detail2</body></html>";
fwrite($fh,$outputdata );
fclose($fh);

 

You can (I hope) see where you would put your html and the $detail1, etc, would be the bits that change taken from the form.

 

Not that while this would work it is totally insecure, so make sure nobody has easy access to it.

 

All the best

 

Keith

 

 

Keith, did somebody tell you today that he loved you? If not, i'm the first. The "$outputdata =" is what I wanted. Thank you in a millioooon!

 

I will test it now.

 

As for the Transaction number, can you tell me how to alter the script to generate transaction numbers in this format:

 

-12 characters in lenght

-only upper case (ZG34GH394GIL) - this is an example.

-start only with ZG

- last 3 characters (ex here GIL) to be the first 3 letters in the $lname of the data I enter.

 

That would be all! THANK ALOT, you made my day!

Link to comment
Share on other sites

Hi

 

Simple way would be to change the line:-

 

$file_name=generate_random_string(8,122);

 

to:-

 

$file_name=strtoupper("ZG".generate_random_string(4,122).strval(rand(100,999)).substr($_POST['Detail1'],0,3));

 

This assumes that the 3 to 6th characters can be numeric as well as alphabetic.

 

All the best

 

Keith

Link to comment
Share on other sites

 

$outputdata = "<html><head></head><body>Various bits of stuff $detail1 some more stuff $detail2</body>

 

You can (I hope) see where you would put your html and the $detail1, etc, would be the bits that change taken from the form.

 

 

Keith

 

 

Keith,

 

One little problem. How can I comment the data  from $outputdata = "<html>...etc</html>" so that it wouldn't give me T_string errors? Because inside that html body I have some other scripts, java etc, and every " or ' is seen as an end to the outputdata, and the color of the text changes from red to black, blue, and to that line it gives me the error. Here is an example:

 

 $outputdata = "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  
  
  <title>°° $monsit -  Espace Client $fname $lname °°</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  
  <meta http-equiv="imagetoolbar" content="no">
  
  <style type="text/css">
<!--
.sf_aereo {
background-image: url("../image/cake.jpg");
background-repeat: no-repeat;
background-position: right top;
}

-->

....etc" 

 

 

Can somebody help me so it wouldn't give me errors? Should I transform all the html to php? Like this?

 

$outputdata = "echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";

echo "<html>\n";

echo "<head>\n";

echo "  \n";

echo "  \n";

echo "  <title>°° $monsit -  Espace Client $lname °°</title>\n";

echo "  <meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n";"

Link to comment
Share on other sites

Hi

 

You could output a line at a time. Might make it easier to spot the problem, but not really solve it.

 

It you have a string surrounded by double quotes (") then any double quote within it will naturally be treated as the end of that string. To get round this you use a \ before any double quote within the string.

 

All the best

 

Keith

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.