Archive for February, 2008

Chapter 15 . Perl Development (Web hosts) 445 $wcartist =

Monday, February 18th, 2008

Chapter 15 . Perl Development 445 $wcartist = % . $artist . % ; $quotedartist = $dbh->quote($wcartist); if ($query) { $query = $query . and artist like $quotedartist ; $search = $search . and $artist ; } else { $query = artist like $quotedartist ; $search = $artist ; } } if ($description eq Yes ) { $wcdesc = % . $description . % ; $quoteddescription = $dbh->quote($wcdesc); $additional_search = or description like $quoteddescription ; } else { $additional_search = ; } if (! $searchterm) { print Please go back and enter at least one search term

n ; exit; } $query1 = SELECT name,artist,description,price,quantity FROM product WHERE ($query $additional_search) ; print $query1

n ; $sth1 = $dbh->prepare($query1); $sth1->execute; print Search results for $search

n ; while (($ename,$eartist,$edesc,$eprice,$equantity) = $sth1 >fetchrow_array()) { $found = 1; print $ename: $eartist - $edesc

n ; if ($equantity > 50) { print - Price: $$eprice. Usually ships in 24 hours.

n ; } elsif ($equantity < 50) { print - Price: $$eprice. Usually ships in 2 to 3 days.

n ; } } if (! $found) { print No products found matching $name $artist

n ; } exit; } print Error ; exit;
You want to have a cheap webhost for your apache application, then check apache web hosting services.

Web site directory - 444 Part IV . Development if (! $dbh)

Sunday, February 17th, 2008

444 Part IV . Development if (! $dbh) { print Connection failed!!

; die(); } if ($simple) { # Look for a product if (! $search) { print Please go back and enter at least one search term

n ; exit; } $wcsearch = % . $search . % ; $quotedsearch = $dbh->quote($wcsearch); $query1 = SELECT name,artist,description,price,quantity FROM product WHERE (name like $quotedsearch or artist like $quotedsearch) ; $sth1 = $dbh->prepare($query1); $sth1->execute; print Search results for $search

n ; while (($ename,$eartist,$edesc,$eprice,$equantity) = $sth1 >fetchrow_array()) { $found = 1; print $ename: $eartist - $edesc

n ; if ($equantity > 100) { print - Price: $$eprice. Usually ships in 24 hours.

n ; } elsif ($equantity < 51) { print - Price: $$eprice. Usually ships in 2 to 3 days.

n ; } elsif ($equantity > 50) { print - Price: $$eprice. Usually ships in 2 to 3 days.

n ; } } if (! $found) { print No products found like $search

n ; } exit; } #If using full search page elsif ($full) { if ($name ne ) { $searchterm = 1; $wcname = % . $name . % ; $quotedname = $dbh->quote($wcname); $query = name like $quotedname ; $search = $name ; } if ($artist ne ) { $searchterm = 1;
We recommend cheap and reliable webhost to host and run your web applications: Coldfusion Web Hosting services.

Web hosting companies - Chapter 15 . Perl Development 443 Figure 15-53:

Saturday, February 16th, 2008

Chapter 15 . Perl Development 443 Figure 15-53: The full search page The code to make the search functions work is as follows: #!/usr/bin/perl use DBI; use CGI qw( :standard ); # Get the input from the form. $name = param( name ); $artist = param( artist ); $search = param( search ); $description = param( description ); $simple = param( simple ); $full = param( full ); # Print an HTML header print Content-Type: text/htmlnn ; # Connect to the database $dbh = DBI->connect( DBI:mysql:ecommerce: ,suehring, evh5150 );
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.

Msn web hosting - 442 Part IV . Development The simple search

Friday, February 15th, 2008

442 Part IV . Development The simple search page is shown in Figure 15-52. Figure 15-52: The simple search page The HTML for producing the full search page looks like this:


Product Name:

Artist/Author/Actor:

Search item description? Yes No

The full search page is shown in Figure 15-53.
Please visit Domain Name Hosting services for high quality webhost to host and run your jsp applications.

Chapter 15 . Perl Development 441 categories, and (Anonymous web server)

Thursday, February 14th, 2008

Chapter 15 . Perl Development 441 categories, and so on. Look back at the example in the previous section for a simple search function with the DBI. The next section develops a product search engine. Figure 15-51: The confirm page produced by the inventory program Note Please add some inventory to your sample database, using the inventory program or any other method. You ll need it for the next section. Building a simple product search engine To get the full benefit of this section, make sure you ve added a few (or more) products to your database. This section builds a search engine to look for products in the database. The basis for the search engine is (again) a static page, which then links to a CGI to produce dynamic pages with the results. I ll be making a simple search box that would probably go on the main page of the site and a more complicated search page with more options (probably a separate page). Here is the HTML that produces the simple search page or box:



In case you need quality webspace to host and run your web applications, try our personal web hosting services.

440 Part IV . Development The program doesn t (Web hosting company)

Wednesday, February 13th, 2008

440 Part IV . Development The program doesn t introduce any new concepts, so I ll just highlight some of its inner workings. The program makes use of the percent sign (%) as a wildcard in the SQL queries. The program accepts input from a form and does some simple error checking on the incoming data. If the first Submit button was clicked, the program then queries the product database for a similar product. If a similar product is found, a page is sent to the user, with information about the existing product (see Figure 15-50). Figure 15-50: A similar product was found in the database, therefore this page is produced with results from the database query. If no similar product is found, a confirmation page is produced as shown in Figure 15-51. Notice on that page that the existing values are included as hidden form tags; you don t see them in Figure 15-51 but, they exist if you view the page source. When the confirm button is clicked, those hidden formtags are passed back to the server the same as with any other form. Finally, if the Confirmed button were clicked, the program adds the product to the database. To develop this further, ideally you would add a method by which more than one item could be added at once. In addition, a method to search for Manufacturer or Category IDis needed. Many additional database tables and columns could be added with items such as warehousing, date of release, other formats, multiple
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.

Chapter 15 . Perl Development 439 print Found (Linux web host)

Tuesday, February 12th, 2008

Chapter 15 . Perl Development 439 print Found a similar product:

n ; print $ename - $eartist - $edesc

n ; exit; } #No existing product found, so print a confirm page. print Confirm product addition

n ; print

n ; print

n ; print

n ; print

n ; print

n ; print

n ; print

n ; print

n ; print Name: $name

Artist: $artist

Price: $$price

n ; print Quantity: $quantity

Manufacturer ID: $manu_id

Category: $category_id

n ; print Description: $description

n ; print

n ; print

; print ; } #If user confirmed that it s ok, then add it. elsif ($confirmed) { $quotedname = $dbh->quote($name); $quotedartist = $dbh->quote($artist); $quoteddescription = $dbh->quote($description); $ins_statement = INSERT INTO product (name,artist,price,quantity,manu_id,description,category_id) VALUES ($quotedname,$quotedartist, $price , $quantity , $manu_id ,$quo teddescription, $category_id ) ; $sth = $dbh->do($ins_statement); if (! $sth) { print Apparently an error occured with the statement

n ; print $ins_statement

n ; exit; } else { print $name added

n ; } } exit;
We recommend cheap and reliable webhost to host and run your web applications: Coldfusion Web Hosting services.

438 Part IV . Development $quantity = param( quantity );

Tuesday, February 12th, 2008

438 Part IV . Development $quantity = param( quantity ); $manu_id = param( manu_id ); $description = param( description ); $submit = param( submit ); $category_id = param( category_id ); $confirmed = param( confirmed ); $price =~ s/s//g; $quantity =~ s/s//g; $manu_id =~ s/s//g; # Print an HTML header print Content-Type: text/htmlnn ; # Test to make sure the user entered enough information. if ((! $name) || (! $price) || (! $quantity)){ print Not enough info specified.

; exit; } elsif ($price =~ /D.?D$/) { print Please enter only digits and decimal point for price.

n ; exit; } elsif ($quantity =~ /D/) { print Please enter only digits for quantity.

n ; exit; } # Connect to the database $dbh = DBI->connect( DBI:mysql:ecommerce: ,suehring, evh5150 ); if (! $dbh) { print Connection failed!!

; die(); } if ($submit) { # Look for a similar product to make sure we re not # adding a duplicate. $wcname = % . $name . % ; $wcartist = % . $artist . % ; $wcdescription = % . $description . % ; $quotedname = $dbh->quote($wcname); $quotedartist = $dbh->quote($wcartist); $quoteddescription = $dbh->quote($wcdescription); $query1 = SELECT name,artist,description FROM product WHERE name like $quotedname and artist like $quotedartist ; $sth1 = $dbh->prepare($query1); $sth1->execute; while (($ename,$eartist,$edesc) = $sth1->fetchrow_array()) {
Please visit Domain Name Hosting services for high quality webhost to host and run your jsp applications.

Web hosting domain names - Chapter 15 . Perl Development 437 Price: $

Monday, February 11th, 2008

Chapter 15 . Perl Development 437

Price: $

Quantity on hand:

Manufacturer:

Category:

Short Description:

Figure 15-49: A static page for entering inventory The CGI to add the products to the database is as follows: #!/usr/bin/perl use DBI; use CGI qw( :standard ); # Get the input from the form. $name = param( name ); $artist = param( artist ); $price = param( price );
If you are searching for cheap webhost for your web application, please visit MySQL5 Web Hosting services.

436 Part IV (Web design company) . Development price decimal(9,2), quantity

Sunday, February 10th, 2008

436 Part IV . Development price decimal(9,2), quantity integer, manu_id int, description varchar(255), category_id int ); CREATE TABLE producttype ( id int NOT NULL PRIMARY KEY, category varchar(50) ); Note If you have the ecommercedatabase on your server now, it would be a good time to drop the database and start over with a fresh version, using the layout listed in this section. One table, cardtype, needs to have a couple of credit card types entered into it. I could build a Web page and CGI for this purpose, but this data doesn t change frequently. Manual entry is quicker if all you need put in the database is the two card types that the site accepts. INSERT INTO cardtype VALUES (1, Visa ); INSERT INTO cardtype VALUES (2, Mastercard ); Related to the cardtypeinput, the producttypetable also needs to be populated with some initial data. I ll be selling music, movies, books, and video games at the site so I ll use three product types or categories. INSERT INTO producttype VALUES (1, CD ); INSERT INTO producttype VALUES (2, DVD ); INSERT INTO producttype VALUES (3, Book ); INSERT INTO producttype VALUES (4, PC CD-ROM Video Game ); Building an inventory-input program The first step to getting the site online is to get products listed in the database so people can locate them and buy them. To accomplish this task, I build a CGI that enables easy input of inventory items. A static Web page can be used as the initial form for input. To input any of the four product types I ll need to enter the name of the product, the artist or author, the price, quantity on hand, the manufacturer if applicable, and a short description of the product. The simple static page is shown in Figure 15-49; the HTML to produce that page is as follows:

Name of product:

Artist/Author/Actor/Producer
If you are in need for chaep and reliable webhost to host your website, our recommendation is http web server services.