Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 214
  • Last Modified:

Script to read the database and create pages for each record in the database.

I have several products I need to provide a download page for. Each page has basically the same information except URL, title, and name of product the URL points to.

What is the code that will allow me to create a flat file database where I can put a file hadle, name of product, URL, HTML page separated by a charater like this:

QUEST | eBay Marketing Secrets | https://supersys2000.com/SUPERPAK_2/ebay.zip | ebay_zip.html

I won't the script to read the database and create pages for each record in the database. How do I do that?

Thanks,
0
QUESTOMNI
Asked:
QUESTOMNI
  • 12
  • 8
1 Solution
 
TintinCommented:
To create it, do:

my $dbfile='/path/to/file';
open DB, ">>$dbfile" or die "Can not open $dbfile $!\n";
print DB "QUEST | eBay Marketing Secrets | https://supersys2000.com/SUPERPAK_2/ebay.zip | ebay_zip.html\n";
close DB;
0
 
QUESTOMNIAuthor Commented:
QUEST | eBay Marketing Secrets | https://supersys2000.com/SUPERPAK_2/ebay.zip | ebay_zip.html

That is one of the records. Here are more records:

QUEST| eBay Marketing Secrets | https://supersys2000.com/SUPERPAK_2/ebay.zip |ebay_zip.html
QUEST1| Classified Ad Secrets |https://supersys2000.com/SUPERPAK_2/classified.zip |classified_zip.html
QUEST2| Credit Secrets | https://supersys2000.com/SUPERPAK_2/credit.zip | credit_zip.html
QUEST3| Wholesale sources | https://supersys2000.com/SUPERPAK_2/wholesale.zip | wholesale_zip.html
QUEST4| Self-publish at the Speed of Thought | https://supersys2000.com/SUPERPAK_2/thought.exe | thought_exe.html

I have 30 records in all. I want a webpage for each created from my database. QUEST is the name of the file handle, then name of the product, then URL, then name of file to create.

Here is the webpage templet:


<HTML
<HEAD>
  <META NAME="GENERATOR" CONTENT="Adobe PageMill 2.0 Win">
  <TITLE>NAME_00</TITLE>
</HEAD>
<BODY ALINK="#800080" VLINK="#00ffff" BGCOLOR="#005100">

<P><CENTER><TABLE WIDTH="350" BORDER="0" CELLSPACING="0" CELLPADDING="0">
<TR>
<TD WIDTH="100%" BGCOLOR="#002f17">&nbsp;</TD></TR>
<TR>
<TD WIDTH="100%" BGCOLOR="#002f17"><P><CENTER>&nbsp;<A HREF="http://supersys2000.com/images/supersystem2.jpg"
TARGET="_top"><IMG SRC="http://supersys2000.com/images/supersystem2.jpg"
ALIGN="BOTTOM" BORDER="0"></A></CENTER></TD></TR>
<TR>
<TD WIDTH="100%" BGCOLOR="#002f17">&nbsp;</TD></TR>
</TABLE>


</CENTER></P>

<H2><CENTER><FONT COLOR="#00e8e8">NAME_00 DOWNLOAD</FONT></CENTER></H2>

<H2><CENTER>&nbsp;</CENTER></H2>

<H2><CENTER><A HREF="URL"
TARGET="_top">NAME_00</A></CENTER></H2>

<H2><CENTER>&nbsp;</CENTER></H2>

<H2><CENTER><FONT COLOR="#00e8e8">ENJOY!</FONT> </CENTER></H2>
</BODY>
</HTML

0
 
TintinCommented:
my $dbfile='/path/to/file';
open DB, $dbfile or die "Can not open $dbfile $!\n";

while (<DB>) {
  chomp;
   my ($handle,$product,$url,$file) = split(/\|/);
   open FILE, ">$file" or die "Can not create $file $!\n";

   print FILE <<EOF;
 <HTML
<HEAD>
  <META NAME="GENERATOR" CONTENT="Adobe PageMill 2.0 Win">
  <TITLE>$Product</TITLE>
</HEAD>
<BODY ALINK="#800080" VLINK="#00ffff" BGCOLOR="#005100">

<P><CENTER><TABLE WIDTH="350" BORDER="0" CELLSPACING="0" CELLPADDING="0">
<TR>
<TD WIDTH="100%" BGCOLOR="#002f17">&nbsp;</TD></TR>
<TR>
<TD WIDTH="100%" BGCOLOR="#002f17"><P><CENTER>&nbsp;<A HREF="http://supersys2000.com/images/supersystem2.jpg"
TARGET="_top"><IMG SRC="http://supersys2000.com/images/supersystem2.jpg"
ALIGN="BOTTOM" BORDER="0"></A></CENTER></TD></TR>
<TR>
<TD WIDTH="100%" BGCOLOR="#002f17">&nbsp;</TD></TR>
</TABLE>


</CENTER></P>

<H2><CENTER><FONT COLOR="#00e8e8">NAME_00 DOWNLOAD</FONT></CENTER></H2>

<H2><CENTER>&nbsp;</CENTER></H2>

<H2><CENTER><A HREF="$url"
TARGET="_top">NAME_00</A></CENTER></H2>

<H2><CENTER>&nbsp;</CENTER></H2>

<H2><CENTER><FONT COLOR="#00e8e8">ENJOY!</FONT> </CENTER></H2>
</BODY>
</HTML
EOF

  close FILE;
}
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
QUESTOMNIAuthor Commented:
IT'S NOT PRINTING. I MADE SURE THE FOLDER WAS 755 THE WEBPAGES ARE TO BE CREATED IN AND STILL CAN'T GET SCRIPT TO WORK.

COULD IT BE YOU ARE USING ONE FILE HANDLE FOR ALL PAGES? HOW CAN WE HAVE THE FILE HANDLE TO CHANGE FOR EACH PAGE TO BE CREATED. I DID TRY TO ACCOUNT FOR THAT IN MY DATABASE. HOW WOULD USE THEM? THEY ALL START WITH "QUEST"
0
 
TintinCommented:
What is your definition of a "file handle"?  I suspect it is different from the common meaning.

How are you determining it is not "printing" (I assume you mean creating the file)?  Do you get any error messages?
0
 
QUESTOMNIAuthor Commented:
The file handle replaces the address of the actual file.

It's not creating the files and I get no error message.
0
 
QUESTOMNIAuthor Commented:
Here's what I'm scripting as you suggested:

#!/usr/local/bin/perl5.00502
print "Content-type:text/html\n\n";

open(DB, "/home/wh36824/public_html/EBOOK_PROCESS/freetosell_ebooks_createsites.db") or dienice("Can't open DB: $1 \n");
while (<DB>) {
  chomp;
   my ($handle,$product,$url,$file) = split(/\|/);
   open FILE, ">/home/wh36824/public_html/EBOOKS/$file" or die "Can not create $file $!\n";

 print FILE <<EOF;
<HTML>
<HEAD>
<META NAME="GENERATOR" CONTENT="Adobe PageMill 2.0 Win">
<TITLE>$product</TITLE>
</HEAD>
<BODY ALINK="#800080" VLINK="#00ffff" BGCOLOR="#005100">

<P><CENTER><TABLE WIDTH="350" BORDER="0" CELLSPACING="0" CELLPADDING="0">
<TR>
<TD WIDTH="100%" BGCOLOR="#002f17">&nbsp;</TD></TR>
<TR>
<TD WIDTH="100%" BGCOLOR="#002f17"><P><CENTER>&nbsp;<A HREF="http://supersys2000.com/images/supersystem2.jpg"
TARGET="_top"><IMG SRC="http://supersys2000.com/images/supersystem2.jpg"
ALIGN="BOTTOM" BORDER="0"></A></CENTER></TD></TR>
<TR>
<TD WIDTH="100%" BGCOLOR="#002f17">&nbsp;</TD></TR>
</TABLE>


</CENTER></P>

<H2><CENTER><FONT COLOR="#00e8e8">$product DOWNLOAD</FONT></CENTER></H2>

<H2><CENTER>&nbsp;</CENTER></H2>

<H2><CENTER><A HREF="$url"
TARGET="_top">$product</A></CENTER></H2>

<H2><CENTER>&nbsp;</CENTER></H2>

<H2><CENTER><FONT COLOR="#00e8e8">ENJOY!</FONT> </CENTER></H2>
</BODY>
</HTML>
EOF

  close FILE;
}

0
 
TintinCommented:
Are you saying that there are *NO* files at all created under /home/wh36824/public_html/EBOOKS?

I find that very difficult to believe if you don't get any errors running the script.
0
 
QUESTOMNIAuthor Commented:
Right, No files at all created under /home/wh36824/public_html/EBOOKS?
I can't see why. There are several pages being created at the same time. It may need delays of some type.
0
 
QUESTOMNIAuthor Commented:
Did you try it on your server?
0
 
TintinCommented:
Yes, I ran it on my server and it works perfectly.

Using your sample DB, I have the following files created:

ebay_zip.html
classified_zip.html
credit_zip.html
wholesale_zip.html
thought_exe.html

What do you mean "there are several pages being created at the same time"?
0
 
QUESTOMNIAuthor Commented:
Please show me the exact script you used and tell me what folder you ran the script from.
0
 
TintinCommented:
I ran it from the command line in my home directory

#!/usr/bin/perl

my $dbfile='dbfile';
open DB, $dbfile or die "Can not open $dbfile $!\n";

while (<DB>) {
  chomp;
   my ($handle,$product,$url,$file) = split(/\|/);
   open FILE, ">$file" or die "Can not create $file $!\n";

   print FILE <<EOF;
 <HTML
<HEAD>
  <META NAME="GENERATOR" CONTENT="Adobe PageMill 2.0 Win">
  <TITLE>$Product</TITLE>
</HEAD>
<BODY ALINK="#800080" VLINK="#00ffff" BGCOLOR="#005100">

<P><CENTER><TABLE WIDTH="350" BORDER="0" CELLSPACING="0" CELLPADDING="0">
<TR>
<TD WIDTH="100%" BGCOLOR="#002f17">&nbsp;</TD></TR>
<TR>
<TD WIDTH="100%" BGCOLOR="#002f17"><P><CENTER>&nbsp;<A HREF="http://supersys2000.com/images/supersystem2.jpg"
TARGET="_top"><IMG SRC="http://supersys2000.com/images/supersystem2.jpg"
ALIGN="BOTTOM" BORDER="0"></A></CENTER></TD></TR>
<TR>
<TD WIDTH="100%" BGCOLOR="#002f17">&nbsp;</TD></TR>
</TABLE>


</CENTER></P>

<H2><CENTER><FONT COLOR="#00e8e8">NAME_00 DOWNLOAD</FONT></CENTER></H2>

<H2><CENTER>&nbsp;</CENTER></H2>

<H2><CENTER><A HREF="$url"
TARGET="_top">NAME_00</A></CENTER></H2>

<H2><CENTER>&nbsp;</CENTER></H2>

<H2><CENTER><FONT COLOR="#00e8e8">ENJOY!</FONT> </CENTER></H2>
</BODY>
</HTML
EOF

  close FILE;
}
0
 
QUESTOMNIAuthor Commented:
Please run it from a folder in which the pages are to be create. I am unfamiliar with command line operations on my system.
0
 
TintinCommented:
I run it both ways, from the command line and from the browser and it works perfectly for all cases.

You still haven't answered my question:

"What do you mean "there are several pages being created at the same time"?
0
 
QUESTOMNIAuthor Commented:
Sorry for not getting back to you until now. I had several personal matters to attend to and have been trying to find out about Telnet access to my server.

What I mean about several pages being created at the same time is each record has one page being created for it if the script works properly. They may not be the same exact time but near the same time. I misspoke. There could be something wrong with my service. I should be able to get back to you tomorrow.  

Thanks
0
 
QUESTOMNIAuthor Commented:
What is wrong with my script? It's not working. My perl debugger says it's good.

*************************************

#!/usr/bin/perl
print "Content-type:text/html\n\n";


my $dbfile= '/home/wh36824/public_html/EBOOKS/freetosell_ebooks_createsites.db';
open (DB, "$dbfile") or die "Can not open $dbfile $!\n";

while (<DB>) {
  chomp;
   my ($handle,$product,$url,$file) = split(/\|/);
   open FILE, ">$file" or die "Can not create $file $!\n";

print FILE <<EOF;
<HTML
<HEAD>
  <META NAME="GENERATOR" CONTENT="Adobe PageMill 2.0 Win">
  <TITLE>$product</TITLE>
</HEAD>
<BODY ALINK="#800080" VLINK="#00ffff" BGCOLOR="#005100">

<P><CENTER><TABLE WIDTH="350" BORDER="0" CELLSPACING="0" CELLPADDING="0">
<TR>
<TD WIDTH="100%" BGCOLOR="#002f17">&nbsp;</TD></TR>
<TR>
<TD WIDTH="100%" BGCOLOR="#002f17"><P><CENTER>&nbsp;<A HREF="http://supersys2000.com/images/supersystem2.jpg"
TARGET="_top"><IMG SRC="http://supersys2000.com/images/supersystem2.jpg"
ALIGN="BOTTOM" BORDER="0"></A></CENTER></TD></TR>
<TR>
<TD WIDTH="100%" BGCOLOR="#002f17">&nbsp;</TD></TR>
</TABLE>


</CENTER></P>

<H2><CENTER><FONT COLOR="#00e8e8">NAME_00 DOWNLOAD</FONT></CENTER></H2>

<H2><CENTER>&nbsp;</CENTER></H2>

<H2><CENTER><A HREF="$url"
TARGET="_top">NAME_00</A></CENTER></H2>

<H2><CENTER>&nbsp;</CENTER></H2>

<H2><CENTER><FONT COLOR="#00e8e8">ENJOY!</FONT> </CENTER></H2>
</BODY>
</HTML
EOF

  close FILE;
}

0
 
TintinCommented:
There's nothing wrong with the script.  The "problem" must be elsewhere.
0
 
QUESTOMNIAuthor Commented:
Someone please write me a script that creates my HTML page for each record in the flat file database.

Here is the database:


QUEST| eBay Marketing Secrets | https://supersys2000.com/SUPERPAK_2/ebay.zip |ebay_zip.html
QUEST1| Classified Ad Secrets |https://supersys2000.com/SUPERPAK_2/classified.zip |classified_zip.html
QUEST2| Credit Secrets | https://supersys2000.com/SUPERPAK_2/credit.zip | credit_zip.html
QUEST3| Wholesale sources | https://supersys2000.com/SUPERPAK_2/wholesale.zip | wholesale_zip.html
QUEST4| Self-publish at the Speed of Thought | https://supersys2000.com/SUPERPAK_2/thought.exe | thought_exe.html
QUEST5| A Cheap and Easy Guide To Self-publishing eBooks| https://supersys2000.com/SUPERPAK_2/selfpub.exe | selfpub_exe.html
QUEST6| Your eBook Daily Marketing Plan | https://supersys2000.com/SUPERPAK_2/edmplan.exe | edmplan_exe.html
QUEST7| How to be a Mystery Shopper | https://supersys2000.com/SUPERPAK_2/mysteryshopper.exe | mysteryshopper_exe.html
QUEST8| UK-Traders UK Wholesale guide | https://supersys2000.com/SUPERPAK_2/wholesalejan2002.exe | wholesalejan2002_exe.html
QUEST9| Living off the Net | https://supersys2000.com/SUPERPAK_2/living.zip | living_zip.html
QUEST10| Working with ClickBank | https://supersys2000.com/SUPERPAK_2/clickbook.pdf | clickbook_pdf.html
QUEST11| Million Dollar emails | https://supersys2000.com/SUPERPAK_2/mde.zip | mde_zip.html

QUEST12| Professional Cover Creation Tutorial  | https://supersys2000.com/SUPERPAK_2/ebct1.exe | ebct1_exe.html
QUEST13| Covers1| https://supersys2000.com/SUPERPAK_2/Covers1.zip | Covers1_zip.html
QUEST14| Covers2| https://supersys2000.com/SUPERPAK_2/Covers2.zip | Covers2_zip.html
QUEST15| Text-to-Speech Engine | https://supersys2000.com/SUPERPAK_2/TTS.zip | TTS_zip.html

QUEST16| Internet Cash Machines | https://supersys2000.com/SUPERPAK_2/cashmachines.zip | cashmachines_zip.html
QUEST17| 1001 Newbie-Friendly Tips  | https://supersys2000.com/SUPERPAK_2/tipspdf.zip | tipspdf_zip.html
QUEST18| AutoResponder Magic | https://supersys2000.com/SUPERPAK_2/autorespondermagic.zip | autorespondermagic_zip.html
QUEST19| E-Mail Marketing Strategies | https://supersys2000.com/SUPERPAK_2/email.exe | email_exe.html
QUEST20| eBay Marketing eCourse | https://supersys2000.com/SUPERPAK_2/ebayms.zip | ebayms_zip.html
QUEST21| The Internet Marketers Secret Guide | https://supersys2000.com/SUPERPAK_2/marketer.exe | marketer_exe.html
QUEST22| The Ultimate eLibrary | https://supersys2000.com/SUPERPAK_2/elib.exe | elib_exe.html
QUEST23| InterNETACTIVE | https://supersys2000.com/SUPERPAK_2/ina.zip | ina_zip.html
QUEST24| iNet Success  | https://supersys2000.com/SUPERPAK_2/inet.exe | inet_exe.html
QUEST25| The eBook Cover Templates | https://supersys2000.com/SUPERPAK_2/ebcover.exe | ebcover_exe.html
QUEST26| The Cash Flow e-Business | https://supersys2000.com/SUPERPAK_2/cashflow.exe | cashflow_exe.html
QUEST27| The Complete Guide to Building Your Own Web Site  | https://supersys2000.com/SUPERPAK_2/byows.exe | byows_exe.html
QUEST28| Free eZine Ad System  | https://supersys2000.com/SUPERPAK_2/freeadsystem.exe | freeadsystem_exe.html
QUEST29| Pay-Per-Click Commando  | https://supersys2000.com/SUPERPAK_2/ppccommando.exe | ppccommando_exe.html
QUEST30| Millionaire Marketing  | https://supersys2000.com/SUPERPAK_2/millionaire_marketing.zip  | millionaire_marketing_zip.html

***************************************************
Here is the page I want created:

<HEAD>
  <META NAME="GENERATOR" CONTENT="Adobe PageMill 2.0 Win">
  <TITLE>$product</TITLE>
</HEAD>
<BODY ALINK="#800080" VLINK="#00ffff" BGCOLOR="#005100">

<P><CENTER><TABLE WIDTH="350" BORDER="0" CELLSPACING="0" CELLPADDING="0">
<TR>
<TD WIDTH="100%" BGCOLOR="#002f17">&nbsp;</TD></TR>
<TR>
<TD WIDTH="100%" BGCOLOR="#002f17"><P><CENTER>&nbsp;<A HREF="http://supersys2000.com/images/supersystem2.jpg"
TARGET="_top"><IMG SRC="http://supersys2000.com/images/supersystem2.jpg"
ALIGN="BOTTOM" BORDER="0"></A></CENTER></TD></TR>
<TR>
<TD WIDTH="100%" BGCOLOR="#002f17">&nbsp;</TD></TR>
</TABLE>


</CENTER></P>

<H2><CENTER><FONT COLOR="#00e8e8">NAME_00 DOWNLOAD</FONT></CENTER></H2>

<H2><CENTER>&nbsp;</CENTER></H2>

<H2><CENTER><A HREF="$url"
TARGET="_top">NAME_00</A></CENTER></H2>

<H2><CENTER>&nbsp;</CENTER></H2>

<H2><CENTER><FONT COLOR="#00e8e8">ENJOY!</FONT> </CENTER></H2>
</BODY>
</HTML
EOF
0
 
QUESTOMNIAuthor Commented:
Hello  Tintin,

Thank you very much for the time you spent with me and getting me as far as you did. You might take a look at what  FishMonger did on the other question I entered to solve the problem. It worked the first time out of the gate. I'm amazed at the work you guys do and very thankful for the help given.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 12
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now