Showing posts with label CGI. Show all posts
Showing posts with label CGI. Show all posts

Tuesday, 9 February 2016

How to Insert HTML Values Into an Oracle DatabaseIn Feburary 2016 09,

In Feburary 2016 09,
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.'
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 -wuse 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.
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;
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 'Information accepted';
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.'
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.
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.
In Feburary 2016 09,