eHow launches Android app: Get the best of eHow on the go.

How To

How to Insert HTML Values Into an Oracle Database

Contributor
By eHow Contributing Writer
(0 Ratings)
Insert HTML Values Into an Oracle Database
Insert HTML Values Into an Oracle Database
http://images.businessweek.com/ss/06/07/top_brands/image/oracle.jpg

There are three basic elements to inserting HTML values into an Oracle database: (1) the HTML form, (2) the server side script and (3) access to the Oracle database on the server. Three different languages must be used to complete the task: HTML for the web page, PERL for the server side script and SQL for sending values to the database. Alternatively, PHP or any other language could be used for the server side script. However, PERL is very well known and can be found, along with its modules, on most all servers. Learn how to send HTML values of a mock web page to an Oracle database.

Difficulty: Moderately Challenging
Instructions

Things You'll Need:

  • Text editor
  • Access to Oracle with user name and password
  1. Step 1

    Create the web page in HTML. Make sure the page includes two text input fields named "user" and "password." Set the form action to call "input.cgi" from the cgi-bin on your server. Save the HTML as "info.html."

  2. Step 2

    Create the server side script. For PERL to speak to a database, you must use the DBI module. The following script shows how to connect to the database:
    #!/usr/bin/perl -w
    use CGI;
    use DBI;
    print "Content-type: text/html\n\n";
    $cgi = CGI->new();
    $user = $cgi->param('user');
    $password = $cgi->param('password');
    $dbh = DBI->connect( "dbi:Oracle:your_Database_name", "your_username", "your_password" )
    or die "Can't connect to Oracle database: $DBI::errstr\n";
    You must get the values for "your_Database_name," "your_username," and "your_password" from your server administrator. For this tutorial, it is assumed you already have this information.

  3. Step 3

    Write the SQL. To do this, you must have a table set up in Oracle that can receive the two fields. Call the table "user_auth" and make sure it has a column called "user" and another one called "pwd." The following SQL statement will insert the data into the table:
    $sqlstatement="INSERT INTO user_auth VALUES ('$user','$password')";
    $sth=$dbh->prepare($sqlstatement);
    $sth->execute || print $sqlstatement;

  4. Step 4

    Confirm the data have been entered by including a print command. To do this, add the following line of code to the end of the program:
    print "<h3>Information accepted</h3>";
    If this does not print out, then you can be sure the information was not sent. You must go back and check the database settings. Save the script as "input.cgi."

  5. Step 5

    Upload the HTML and CGI files to the server. The HTML must go in docs area, and the CGI must be uploaded to the cgi-bin.

  6. Step 6

    Execute the program. Do this by opening the HTML document in a browser and entering some mock information. Once you submit it, you should see the confirmation printout. If you see the printout, the information has been sent to the database.

Tips & Warnings
  • For Step 1, most web designers will implement some JavaScript to validate the input forms, that is, make sure all forms are filled. This is not necessary for the purpose of this article. Double-check that the information has been sent to the database by going directly into Oracle and checking the "user_auth" table itself. Similar connection procedures are used for all the industrial database programs. For example, to use MySQL, you only have to change the connection syntax minimally. This is a very small amount of input. You can modify the program to accommodate hundreds of fields. Oracle is a very solid platform and can handle large amounts of data.
  • The commas and semicolons in the script examples are part of the script. You must include them or the script will fail to execute. If you do not see the confirmation printout, there has been a connection problem. If you get an "Internal Server" error, there is a programming issue, such as poorly written syntax. Most servers will require you to "chmod 755" your script or you will get endless.
Subscribe

Post a Comment

Post a Comment

Related Ads

  • Have you done this? Click here to let us know.
I Did This
Get Free Computers Newsletters

Copyright © 1999-2009 eHow, Inc. Use of this web site constitutes acceptance of the eHow Terms of Use and Privacy Policy .   en-US Portions of this page are modifications based on work created and shared by Google and used according to terms described in the Creative Commons 3.0 Attribution License. † requires javascript

eHow Computers
eHow_eHow Technology and Electronics