Free asp script

Free asp script

ASP Programe About Us Links Downloads Contact Us Terms of use SiteMap
Free asp script
Free asp script

 

You are here: ASP Programe >>Free asp script

Free asp script article lists.

Free asp script

From Script to Database




These days, building Web pages and databases isn't all that difficult. But how do you tie the two together so that some pages let visitors input data from HTML forms and other pages display database information?

The answer lies in server-side scripting frameworks such as Java Server Pages (JSP), PHP, ASP.NET, and ColdFusion. These frameworks let you write HTML documents with islands of code embedded in them. For example, you can start a table with <TABLE>, write some code that fills in a sequence of rows, and close with </TABLE>.Visitors to your Web site will be none the wiser, because they never see the code. If they look at the source of the document, they see only the HTML output generated by your code.

As an alternative to embedding code, you can write programs that emit the entire HTML document. In this article we'll present sample programs that demonstrate how to use various scripting frameworks to read in the values from a static HTML form and insert them into a database.

Our database contains a single table called PEOPLE, with three columns (firstname, lastname, and zipcode). In each program, four things are going to happen. First, we'll pull the form data into local variables inside the program. Second, we'll make a connection to the database. Next, we'll add the new person to the database using the SQL INSERT statement, which will look something like:

INSERT INTO PEOPLE VALUES ('Brian', 'Jepson', '02881')

Finally, the SQL SELECT statement will fetch the names of all the people in the database and will display the names as an HTML table. Even though the examples that follow are written in different languages, they'll all emit roughly the same HTML.

Figure 1 shows the source code for the HTML form Newperson.html. You will need to change changeme.cgi, which is used as a placeholder in the figure, to the name of whatever script receives the form data. We'll do this explicitly in the first example below, so you'll know what to do for the other examples. Figure 2 shows how the form would appear in a Web browser.

The contents of the table will depend on how many people you add to the database. Figure 3 shows how the HTML output looks in a browser.

JSP

JSP combines HTML and the Java programming language. You can add bits of Java, which will execute on the server, to your HTML pages. Java is completely different from (but often confused with) JavaScript, a lightweight language that executes on browsers and uses syntax similar to Java's.

You can get JSP by downloading and installing Tomcat (http://jakarta.apache.org/tomcat), the official reference implementation of JSP and Java Servlets; Tomcat is open-source.

You indicate the start of JSP markup with the <% characters, and you return to HTML after the %> characters. In Figure 4, quite a bit of Java code appears before the first HTML tag. The example uses the JDBC data access API (http://java.sun.com/jdbc) to connect to a PostgreSQL database server (www.postgresql.org).

Partway through the HTML document, this example returns to Java to loop through the results of a SQL SELECT statement. For each row in the results, the loop displays a table row (<TR>) showing the name and ZIP code of each person in the database (the <%= variable %> syntax inserts the variable's value into the HTML). As we noted earlier, you will need to replace the changeme.cgi in Newperson.html with the name of this JSP (Saveperson .jsp) before the HTML form can post data to the JSP.

PHP

PHP (www.php.net) is a scripting language with syntax similar to that of Perl. It was originally written in Perl but was ported to C. PHP is more mature than ASP or JSP.

PHP markup is interspersed with bits of HTML. PHP code is marked off using the delimiters. Although PHP has a simple syntax for connecting to databases, each database has its own set of functions, prefixed with the name of the database. Contrast this with ASP.NET, ColdFusion, JSP, and Perl, in which the functions are the same, regardless of the database you connect to. In those languages, the only thing you need to change is your database connection string. There is one exception to this in ASP.NET: In addition to the framework's generic data provider (the OLE DB provider), ASP.NET offers an optimized provider for SQL Server.

MySQL (www.mysql.com), which is open-source, is the database server most commonly associated with PHP, and you can use the mysql_* functions to interact with this database.

Saveperson.php (Figure 5) connects to a MySQL database as the user bjepson and chooses the database named bjepson (on hosted servers, your MySQL database will typically have the same name as your user name). Next, Saveperson.php inserts the new person into the database. Notice the simplified syntax for creating the SQL statement: In JSP, we had to concatenate the strings using +, but PHP (like Perl) expands variables inside of double-quoted strings. After updating the database, this example displays an HTML page containing the names of all the people in the database (the echo statement inserts a string into the HTML sent to the browser).

Lack of space prevents us from including code examples for the following discussions of ASP.NET, ColdFusion, and Perl.

Asp.Net

ASP.NET is the first major overhaul of the original Active Server Pages (ASP). Sun's JSP improved on ASP (for example, JSP documents are compiled the first time they are loaded, which speeds response time for each subsequent visitor). ASP.NET includes many of the enhancements found in JSP. ASP.NET ships with the .NET Framework, available from http://msdn.microsoft.com/net (it will also ship with the upcoming Windows .NET Server).

Saveperson.aspx is an ASP.NET script that is written in C# and uses the OLE DB data access API to fetch data from and save data to a SQL Server database server. Although you could use the optimized SQL Server data provider, you can easily modify the OLE DB data provider to work with other databases such as Access, DB2, MySQL, and Oracle.

The ASP.NET code that saves the new person to the database is not too different from the other examples. This example opens a connection, creates a SQL statement, and executes that statement. This version does differ in the method we use to display the list of people. Instead of fetching a result set and looping through each row in the result, we create a DataSet, render an HTML table using the special ASP.NET tag , and then bind the table to the data set.

Coldfusion

Macromedia ColdFusion (formerly from Allaire) was one of the earliest commercial Web/database solutions. Since its introduction, it has grown to a full-fledged application server, with capabilities comparable to ASP.NET and JSP/Java Servlets. You'll find a trial edition of ColdFusion at www.macromedia.com.

Saveperson.cfm is our shortest example. Instead of lots of code in a procedural language, ColdFusion uses CFML (ColdFusion Markup Language). With the <cfparam> tag, you can import data from the calling form (Newperson.html), and you can use <cfoutput> to insert something into the HTML.

For database connectivity, the <cfquery> tag lets you query an ODBC data source and give the results of that query a name. In our example, we use <cfquery> to insert a new record. You'll see we use the <cfqueryparam> tag to specify the values to insert. ColdFusion takes care of generating a valid SQL statement, using the information in those tags. Next, we use <cfquery> with SELECT to create the list of people. The results of the SELECT are named MyQuery, which we then associate with a <cftable> object (ASP.NET's <asp:DataGrid> is strikingly similar).

Perl

The Jargon File (www.tuxedo.org/~esr/jargon) refers to Perl as a Swiss Army chainsaw: powerful, versatile, but not at all elegant. You can do a lot with Perl. Aside from Web development, You can use Perl for log-file analysis and data conversion. Perl has great support for Web programming and a great database-access API called DBI (http://dbi.symbolstone.org).

Saveperson.cgi shows how you can use Perl as a CGI application. CGI does not scale as well as the other examples shown here, because CGI scripts run out of process with the Web server. The good news is that most Perl CGI scripts run unchanged using mod_perl (http://perl.apache.org), a Perl plug-in for the Apache Web server.

So Many Choices

The embedded code approach is easier for most Web applications, but it's a good idea to keep CGI scripts and mod_perl in your arsenal as well. There are some cases where they are necessary, especially when you need to generate something other than HTML, such as a PNG or a GIF image.

In case you encounter any of these development frameworks in your travels, these examples should help orient you. You can use any of the solutions covered here to develop great Web/database applications. So how do you select the one to use if you're starting from scratch?

Free asp script Related Links
Free asp shopping cart1 asp host
Asp snakeAsp application
Nt web hosting aspAsp software solution
Asp hosting sqlAsp reporting web
Asp emailAsp editor
Asp pagesAsp web site hosting
Asp .netAsp .net hosting
Use asp in htmlFree asp code
Asp portalAsp excel
Learn aspAsp nt hosting
Apache aspAsp login
Asp net atlantaDefault asp
Asp hosting sharedAsp xml
Asp gratis hostingAsp source code
Asp componentFax asp
Asp date formatAsp hosting mexico
Asp mysql hostingAsp site hosting
Cheap asp hostingAsp surfing
Search aspAsp function
Multimedia asp auto sign mediadisplay refAsp mysql
Asp mailAsp chart
Asp cookieAsp services
Asp sql server web hostingAsp training
Fax service aspAsp include
Asp securityAsp engine
 
©2005 All Rights Reserved   ASP Programe