Вы находитесь на странице: 1из 27

ASP CODE

################# CREATE FRAME ################


<html>
<frameset border=0 bordercolor=#000000 rows = "30%,*" NORESIZE>
<frame src = "Heading2.asp" name="frame3" scrolling=no NORESIZE>
<frameset cols="24%,*">
<frame src = "MainMenu.html" name = "frame1" scrolling = no NORESIZE>
<frame src = "Introduction.html" name = "frame2" scrolling = yes NORESIZE>
</frameset>
</frameset>
</html>
################# SET COOKIE ##############

function setcookie(cname,cvalue)
{
document.cookie = cname + "=" +cvalue;
}
<b>UserName</b> <input type="text" name="username"
onBlur="setcookie(this.name,this.value)">

########
<%
IF BlnIsValidUser = True Then
Response.Cookies("CURRENT_USER")= StrUsername
%>

################# VALIDATION ##############

function IsAlphab(FieldVal)
{
var FieldLength = FieldVal.length;
for (var i=0; i<FieldLength; i++)
{
if (!isNaN(FieldVal.charAt(i)))
{
return (false);
}
}
return (true);
}
function IsInt(FieldVal)
{
var FieldLength = FieldVal.length;
for (var i=0; i<FieldLength; i++)
{
if (isNaN(FieldVal.charAt(i)))
{
return (false);
}
}
return (true);
}

function val1(form2)
{
if(form2.elements[0].value=="")
{
Page 1
ASP CODE
alert(form2.elements[0].name+" must be filled");
document.form2.elements[0].focus();
return(false);
}

if(form2.elements[1].value=="")
{
alert(form2.elements[1].name+" must be filled");
document.form2.elements[1].focus();
return(false);
}

if(form2.elements[2].value=="")
{
alert(form2.elements[2].name+" must be filled");
document.form2.elements[2].focus();
return(false);
}
if(form2.elements[3].value=="")
{
alert(form2.elements[3].name+" must be filled");
document.form2.elements[3].focus();
return(false);
}

if(form2.elements[4].value=="")
{
alert(form2.elements[4].name+" must be filled");
document.form2.elements[4].focus();
return(false);
}
if(form2.elements[5].value=="")
{
alert(form2.elements[5].name+" must be filled");
document.form2.elements[5].focus();
return(false);
}
if(form2.elements[6].value=="")
{
alert(form2.elements[6].name+" must be filled");
document.form2.elements[6].focus();
return(false);
}

if (!IsInt(document.form2.elements[6].value))
{
alert("Telephone number must be integer");
document.form2.elements[6].focus();
return(false);
}

if(form2.elements[7].value=="")
{
alert(form2.elements[7].name+" must be filled");
document.form2.elements[7].focus();
return(false);
}
if(document.form2.elements[7].value != "")
Page 2
ASP CODE
{
pass = document.form2.elements[7].value.indexOf('@',0);
pass1 = document.form2.elements[7].value.indexOf('.',0);
if((pass==-1) || (pass1==-1))
{
alert("Not a valid Email address");
document.form2.elements[7].focus();
return (false);
}
}
if(form2.elements[8].value=="")
{
alert(form2.elements[8].name+" must be filled");
document.form2.elements[8].focus();
return(false);
}
if( (form2.elements[10].value==""))
{
alert(form2.elements[10].name+" must be filled and");
document.form2.elements[10].focus();
return(false);
}

return(true);

<form name="formlogin" action="newuser.asp" method="post" OnLoad=setval()


onSubmit="return check()">

################### DATABASE CONNECTION ################

<%
Dim dcnDB
Dim rsquery
Dim StrUsername, StrPassword, Strpassword1, StrBuyerQuery, StrNewBuyerQuery,
BlnDuplicateBuyer, ObjRSBuyer

StrUsername = Trim(Replace(Request.Form("username"), "'", "''"))


StrPassword = Trim(Replace(Request.Form("Password"), "'", "''"))
Strpassword1 = Trim(Replace(Request.Form("password1"), "'", "''"))
Set dcnDB = Server.CreateObject("ADODB.Connection")
dcnDB.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\bugs.mdb"
dcnDB.Open
Set rsquery = Server.CreateObject("ADODB.Recordset")
rsquery.Open "SELECT * FROM login",dcnDB,1,3
rsquery.AddNew

rsquery("Username") = StrUsername
rsquery("Password") = StrPassword
rsquery.update
rsquery.Close
dcnDB.Close
response.redirect("user.html")
Page 3
ASP CODE
%>

#################### INSERT DATA IN THE DATAABASE #################


<%
Dim dcnDB
Dim rsquery
Dim Strfirstname, Strlastname, Stradd1, Strcity, Strstate, Strcountry,stremail,
StrPhoneNumber, Strsex, Strbranch, BlnDuplicateBuyer, ObjRSBuyer

Strfirstname = Trim(Replace(Request.Form("Firstname"), "'", "''"))


Strlastname = Trim(Replace(Request.Form("Lastname"), "'", "''"))
Stradd1 = Trim(Replace(Request.Form("Add1"), "'", "''"))
Strcity = Trim(Replace(Request.Form("City"), "'", "''"))
Strstate = Trim(Replace(Request.Form("State"), "'", "''"))
Strcountry = Trim(Replace(Request.Form("Country"), "'", "''"))
Strphonenumber = Trim(Replace(Request.Form("Telephone"), "'", "''"))
Stremail = Trim(Replace(Request.Form("Email"), "'", "''"))
Strsex = Trim(Replace(Request.Form("Sex"), "'", "''"))
Strbranch = Trim(Replace(Request.Form("Branch"), "'", "''"))

Set dcnDB = Server.CreateObject("ADODB.Connection")


dcnDB.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\bugs.mdb"
dcnDB.Open

Set rsquery = Server.CreateObject("ADODB.Recordset")


rsquery.Open "SELECT * FROM username",dcnDB,1,3

rsquery.AddNew
rsquery("Firstname") = Strfirstname
rsquery("Lastname") = Strlastname
rsquery("Add1") = Stradd1
rsquery("City") = Strcity
rsquery("State") = Strstate
rsquery("Country") = StrCountry
rsquery("Telephone") = Strphonenumber
rsquery("Email") = Stremail
rsquery("Sex") = Strsex
rsquery("Branch") = Strbranch
rsquery.update

rsquery.Close
dcnDB.Close
response.redirect("report.asp")
%>

############# CREATE SESSION ##############


<%= Session("LoginUser")=REQUEST.FORM("variablename") %>

set rs=Server.CreateObject("ADODB.recordset")

Page 4
ASP CODE
if rs.RecordCount<>0 then
Session("pro_id")=rs.Fields("profile_id")
Session("fname")=rs.Fields("fname")
Session("gender")=rs.Fields("gender")
Response.Cookies("pro_id")=Request("id")

-----------CHEKING SESSION -----------


<%
if Session("LoginUser")="" then
Response.Redirect("register.htm")
end if
<% session.Abandon %>
############## INCLUDE ###################

<%@ Language=VBScript %>


<!-- #INCLUDE FILE="adovbs.inc" -->
<%
########CREATE FILE NAME WITH "ADOVBS"###########
<%
'--------------------------------------------------------------------
' Microsoft ADO
'
' (c) 1996 Microsoft Corporation. All Rights Reserved.
'
'
'
' ADO constants include file for VBScript
'
'--------------------------------------------------------------------

'---- CursorTypeEnum Values ----


Const adOpenForwardOnly = 0
Const adOpenKeyset = 1
Const adOpenDynamic = 2
Const adOpenStatic = 3

'---- MarshalOptionsEnum Values ----


Const adMarshalAll = 0
Const adMarshalModifiedOnly = 1
'---- AffectEnum Values ----
Const adAffectCurrent = 1
Const adAffectGroup = 2
Const adAffectAll = 3
'---- FilterGroupEnum Values ----
Const adFilterNone = 0
Const adFilterPendingRecords = 1
Const adFilterAffectedRecords = 2
Const adFilterFetchedRecords = 3
Const adFilterPredicate = 4
'---- SearchDirection Values ----
Const adSearchForward = 0
Const adSearchBackward = 1

Page 5
ASP CODE
'---- ConnectPromptEnum Values ----
Const adPromptAlways = 1
Const adPromptComplete = 2
Const adPromptCompleteRequired = 3
Const adPromptNever = 4
'---- ConnectModeEnum Values ----
Const adModeUnknown = 0
Const adModeRead = 1
Const adModeWrite = 2
Const adModeReadWrite = 3
Const adModeShareDenyRead = 4
Const adModeShareDenyWrite = 8
Const adModeShareExclusive = &Hc
Const adModeShareDenyNone = &H10
'---- IsolationLevelEnum Values ----
Const adXactUnspecified = &Hffffffff
Const adXactChaos = &H00000010
Const adXactReadUncommitted = &H00000100
Const adXactBrowse = &H00000100
Const adXactCursorStability = &H00001000
Const adXactReadCommitted = &H00001000
Const adXactRepeatableRead = &H00010000
Const adXactSerializable = &H00100000
Const adXactIsolated = &H00100000

'---- XactAttributeEnum Values ----


Const adXactCommitRetaining = &H00020000
Const adXactAbortRetaining = &H00040000
'---- PropertyAttributesEnum Values ----
Const adPropNotSupported = &H0000
Const adPropRequired = &H0001
Const adSchemaForeignKeys = 27
Const adSchemaPrimaryKeys = 28
Const adSchemaProcedureColumns = 29
%>

################# ADD DATABASE VALUE ################################


<html>
<%
Dim dcnDB
Dim rsquery
Dim Strcompanyname, Strpost, Strsalary, Strbranch, BlnDuplicateBuyer, ObjRSBuyer

Strcompanyname = Trim(Replace(Request.Form("companyname"), "'", "''"))


Strpost = Trim(Replace(Request.Form("post"), "'", "''"))
Strsalary = Trim(Replace(Request.Form("salary"), "'", "''"))
Strbranch = Trim(Replace(Request.Form("branch"), "'", "''"))
Set dcnDB = Server.CreateObject("ADODB.Connection")
dcnDB.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\bugs.mdb"
dcnDB.Open
Set rsquery = Server.CreateObject("ADODB.Recordset")
rsquery.Open "SELECT * FROM company",dcnDB,1,3

Page 6
ASP CODE
rsquery.AddNew
rsquery("companyname") = Strcompanyname
rsquery("post") = Strpost
rsquery("salary") = Strsalary
rsquery("branch") = Strbranch

rsquery.update

rsquery.Close

dcnDB.Close
response.redirect("report.asp")
%>
<body background="image321.gif">

</body>

<html>

################## MODIFY DATABASE VALUE ####################

<%
Option Explicit
Dim dcnDB,rsquery,flag,strselect,strcheck,StrUsername,Strpost,Strsalary,Strbranch,
StrPassword, StrLoginQuery,check, BlnIsValidUser, ObjCon, ObjRSLogin

flag=0
StrUsername = Trim(Request.Form("companyname"))
Strpost = Trim(Request.Form("post"))
Strsalary = Trim(Request.Form("salary"))
Strbranch = Trim(Request.Form("branch"))

Set ObjCon = Server.CreateObject("ADODB.Connection")


ObjCon.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=
D:\bugs.mdb"
ObjCon.Open

strselect="select count(*) from company WHERE companyname='"&StrUsername&"'"


set strcheck=objcon.Execute(strselect)

IF strcheck(0) > 0 Then


flag=1
StrLoginQuery = "UPDATE company SET
companyname='"&StrUsername&"',salary='"&Strsalary&"',post='"&strpost&"',branch='"&st
rbranch&"' WHERE companyname='"&StrUsername&"'"
ObjCon.Execute(StrLoginQuery)
objcon.close
%>
<html>
<body>
<META HTTP-EQUIV="refresh";
content="2;url=http://localhost/onlinebugs/modifycomp.asp">
<font face ='Comic sans MS' color='#996633' size=5>
<center><h1>Record Modified Successful !</h1>
</center>
</FONT>
Page 7
ASP CODE
<%
ELSE
%>
<META HTTP-EQUIV="refresh";
content="2;url=http://localhost/onlinebugs/modifycomp.asp">
<font face ='Comic sans MS' color='#996633' size=5>
<center><h1>Company Not Found !</h1>
</center>
</FONT>
</body>
</html>
<%
END IF

%>
################### DELETE DATABASE VALUE ##################

<%
Option Explicit
Dim StrUsername,strLoginQuery,strcheck,strselect, BlnIsValidUser, ObjCon, ObjRSLogin
StrUsername = Trim(Request.Form("companyname"))
Set ObjCon = Server.CreateObject("ADODB.Connection")
ObjCon.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=
D:\bugs.mdb"
ObjCon.Open
strselect="select count(*) from company WHERE companyname='"&StrUsername&"'"
set strcheck=objcon.Execute(strselect)
IF strcheck(0) > 0 Then

StrLoginQuery = "DELETE FROM company WHERE companyname='"&StrUsername&"'"


ObjCon.Execute(StrLoginQuery) %>
<html>
<body>
<META HTTP-EQUIV="refresh";
content="2;url=http://localhost/onlinebugs/deletecomp.asp">
<font face ='Comic sans MS' color='#996633' size=5>
<center><h1>Record Deleted Successful !</h1>
</center>
</FONT>
<%
ELSE
%>
<META HTTP-EQUIV="refresh";
content="2;url=http://localhost/onlinebugs/deletecomp.asp">
<font face ='Comic sans MS' color='#996633' size=5>
<center><h1>Company Not Found !</h1>
</center>
</FONT>
</body>
</html>
<%
END IF

ObjCon.Close
%>
Page 8
ASP CODE

########## STYLE SHEET #####################


table,th,td{
border:1px solid #666;
border-collapse:collapse;
}
table{
border:none;
border-top:1px solid #000;
}
thead th{
background:url(greychrome.gif) top left repeat-x #fff;
padding:5px 10px;
font-size:90%;
text-transform:uppercase;
color:#333;
}
tbody td,tbody th{
font-size:85%;
padding:5px 10px;
background:#eee;
}
tbody th{
background:url(bluechrome.gif) top left repeat-x #fff;
color:#333;
}
tbody tr.odd td{
background:#ddd;
}
tbody tr.odd th{
background:url(greenchrome.gif) top left repeat-x #fff;
color:#333;
}
tfoot td,tfoot th{
border:none;
padding-top:10px;
}
caption{
font-family:Tahoma;
text-align:left;
text-transform:uppercase;
font-size:130%;
padding:10px 0;
color:#036;
}
table a:link{
color:#369;
}
table a:visited{
color:#036;
}
table a:hover{
color:#000;
text-decoration:none;
}
table a:active{
color:#000;
}
BODY {
SCROLLBAR-FACE-COLOR: #fdfdfd; SCROLLBAR-HIGHLIGHT-COLOR: #cc9966;
Page 9
ASP CODE
SCROLLBAR-SHADOW-COLOR: #cc9966; SCROLLBAR-ARROW-COLOR: #cc9966;
SCROLLBAR-TRACK-COLOR: #fdfdfd; SCROLLBAR-BASE-COLOR: #cc9966;
scrollbar-3d-light-color: #cc9966; scrollbar-dark-shadow-color: #cc9966
}

################ CGI CODE


################################################################
####################################################################################
#################################
################## ADMIN VALID ####################
#!c:/perl/bin/perl.exe
print "Content-Type: text/html\n\n";
use DBI;
use DBD::mysql;
$host = "localhost"; # your database server, can be localhost
$database = "consultancy"; # connecting database
$table = "admin"; # table within the database
$dbuser = "root"; # database login userid
$dbpass = ""; # database login password
print "<html>";
print "<BODY bgColor=#fdfdfd>";
if($ENV{'REQUEST_METHOD'}=~ /post/i)
{
read(stdin,$buffer,$ENV{'CONTENT_LENGTH'});
@values=split(/&/, $buffer);

foreach $namevalue(@values)
{
($key, $value)=split(/=/,$namevalue);
$hash{$key}=$value;
}
%hash=decode(%hash);
$dbh =
DBI->connect("DBI:mysql:database=$database;host=$host","$dbuser","$dbpass") || die
"\nDB connection error!\n";
$query = $dbh->prepare("SELECT username,password from admin");
$test=$query->execute();
$flag=1;
while(@row = $query->fetchrow_array())
{
($name,$pass) = @row;
if(($hash{username}=~ /^$name$/) && ($hash{password}=~ /^$pass$/))
{
$flag=0;
last;
}
}
$dummy=0;
if($flag == $dummy)
{
print <<htmllog;
<p>
<p>
<p>
<META HTTP-EQUIV="refresh"; content="2;url=http://localhost/bugs/Adminmenu.html">
<font face ='Comic sans MS' color='#996633' size=5>
<center><h1>Login Successful !</h1>
</center>
Page 10
ASP CODE
htmllog
}
else
{
print <<unsuchtml
<p>
<p>
<p>
<META HTTP-EQUIV="refresh";
content="2;url=http://localhost/bugs/Administrator.html">
<h1><center>Login Fail !</center></h1>
<INPUT TYPE=HIDDEN name="member" value=$hash{membernum}>
</font>
unsuchtml
}

undef($query);
$dbh->disconnect;

}
print "</p></body></html>";
sub decode
{
(%ha)=@_;
foreach $key(keys %ha)
{
$temp=$ha{$key};
$temp=~tr/+/ /;
$temp=~s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
$ha{$key}=$temp;
}
return %ha;
}

####################### INSERT DATA


#########################################################

#!c:/perl/bin/perl.exe
use DBI;
$host = "localhost"; # your database server, can be localhost
$database = "consultancy"; # connecting database
$table = "Username"; # table within the database
$dbuser = "root"; # database login userid
$dbpass = ""; # database login password
$dbh=DBI->connect("dbi:mysql:dbname=consultancy","$dbuser","$dbpass");
print "Content-Type: text/html\n\n";
print <<abc;
<html>
<body bgcolor=#fdfdfd>
<p>
abc
#print "Form request Method : $ENV{'REQUEST_METHOD'}\n";
$cookie=$ENV{HTTP_COOKIE};
if($ENV{'REQUEST_METHOD'}=~ /^GET$/i)
Page 11
ASP CODE
{
@values=split(/&/, $ENV{'QUERY_STRING'});

foreach $namevalue(@values)
{
($key, $value)=split(/=/,$namevalue);
$namevalue = ~ tr/+/ /;
$hash{$key}=$value;
}

%hash=decode(%hash);

}
elsif($ENV{'REQUEST_METHOD'}=~ /^post$/i)
{
read(stdin,$buffer,$ENV{'CONTENT_LENGTH'});

@values=split(/&/, $buffer);

foreach $namevalue(@values)
{
($key, $value)=split(/=/,$namevalue);
$namevalue= ~ tr/+/ /;
$hash{$key}=$value;
# print"$key = $hash{$key}";
}
%hash=decode(%hash);

if(($hash{FirstName}=~ /^$/))
{
print <<htmllog;
<html>
<BODY bgColor=#ccccff>
<p>
<p>
<p>
<META HTTP-EQUIV="refresh"; content="2;url=http://localhost/bugs/User.html">
<center><h1>First Name must be filled !</h1>
</center>
</p></body></html>

htmllog
die;
}
if(($hash{LastName}=~ /^$/))
{
print <<htmllog;
<html>
<BODY bgColor=#ccccff>
<p>
<p>
<p>
<META HTTP-EQUIV="refresh"; content="2;url=http://localhost/bugs/User.html">
<center><h1>LastName must be filled!</h1>
</center>
</p></body></html>
htmllog
Page 12
ASP CODE
die;
}
if(($hash{Add1}=~ /^$/))
{
print <<htmllog;
<html>
<BODY bgColor=#ccccff>
<p>
<p>
<p>
<META HTTP-EQUIV="refresh"; content="2;url=http://localhost/bugs/User.html">
<center><h1>Address must be filled!</h1>
</center>
</p></body></html>
htmllog
die;
}
if(($hash{City}=~ /^$/))
{
print <<htmllog;
<html>
<BODY bgColor=#ccccff>
<p>
<p>
<p>
<META HTTP-EQUIV="refresh"; content="2;url=http://localhost/bugs/User.html">
<center><h1>City must be filled !</h1>
</center>
</p></body></html>

htmllog
die;
}
if(($hash{State}=~ /^$/))
{
print <<htmllog;
<html>
<BODY bgColor=#ccccff>
<p>
<p>
<p>
<META HTTP-EQUIV="refresh"; content="2;url=http://localhost/bugs/User.html">
<center><h1>State must be filled !</h1>
</center>
</p></body></html>
htmllog
die;
}
if(($hash{Country}=~ /^$/))
{
print <<htmllog;
<html>
<BODY bgColor=#ccccff>
<p>
<p>
<p>
<META HTTP-EQUIV="refresh"; content="2;url=http://localhost/bugs/User.html">
<center><h1>Telephone must be filled !</h1>
Page 13
ASP CODE
</center>
</p></body></html>

htmllog
die;
}

# if(($hash{Telephone}=~ /^$/) || ($hash{Telephone}!=~/^[0-9]$/))


# {
# print <<htmllog;
# <html>
# <BODY bgColor=#ccccff>
# <p>
# <p>
# <p>
# <META HTTP-EQUIV="refresh";
content="2;url=http://localhost/bugs/user.html">
# <center><h1>Telephone must be filled ro should be integer!</h1>
# </center>
# </p></body></html>

#htmllog
# die;
# }

if(($hash{Email}=~ /^$/))
{
print <<htmllog;
<html>
<BODY bgColor=#ccccff>
<p>
<p>
<p>
<META HTTP-EQUIV="refresh"; content="2;url=http://localhost/bugs/User.html">
<center><h1>Email must be filled !</h1>
</center>
</p></body></html>

htmllog
die;
}
if( ($hash{Branch}=~ /--/) )
{
print <<htmllog;
<html>
<BODY bgColor=#ccccff>
<p>
<p>
<p>
<META HTTP-EQUIV="refresh"; content="2;url=http://localhost/bugs/User.html">
<center><h1>Branch must be filled !</h1>
</center>
</p></body></html>
htmllog
die;
}

#$query="insert into adduser


Page 14
ASP CODE
values('$hash{FirstName}','$hash{LastName}','$hash{Add1}')";
$query="insert into Username
values('$hash{FirstName}','$hash{LastName}','$hash{Add1}','$hash{City}','$hash{State
}','$hash{Country}',$hash{Telephone},'$hash{Email}','$hash{Sex}','$hash{Branch}')";
$dbh->do($query);
print"<html><body bgcolor=#009999><p><p><p>";
print"<br><br><br><br>";
print"<font size =5 color =\"black\">";
# print"<META HTTP_EQUIV=\"refresh\";
content=\"2;url=http://localhost/bugs/listuser.cgi">";
print"<strong> <center> YOU HAVE SUCCESSFULLY ENTERED THE DATA";
print"<br><br><br>";
print"</center></strong></font>";
print"</p></body></html>";
print <<STARTHTML;
<html>
<head>
<LINK href="1 (9).css" type=text/css rel="stylesheet">
<title>
Available Company Names
</title>
<script language="javascript">
</script>
<body bgcolor=#ccccff>
<img src="image/2.jpg" ><hr>
<form name="frmadd" method="post" action="">
<input type="hidden" name="id" value="">
</form>
<table align="center"
width=90%
cellspacing=0
cellpadding=0
border=1
bordercolor="maroon">
<tr bgcolor="maroon">
<td align="center">
<h2>
List of Available Companies
</h2>
</td>
</tr>
<tr>
<td>
<table align="center"
width=100%
cellspacing=0
cellpadding=0
border=1
bordercolor="black">
<tr>
<th align="center">
Company Name
</th>
<th align="center">
Post
</th>
<th align="center">
Salary
</th>

Page 15
ASP CODE
<th align="center">
Branch
</th>
</tr>
<form name="frmdelete" method="post" action="">
STARTHTML

my $query = $dbh->prepare("SELECT * FROM Company where Branch = '$hash{Branch}'");


$query->execute();
while(@row = $query->fetchrow_array())
{
($CompanyName,$Post,$salary,$Branch)=@row;
print "<tr bgcolor=\"#ccccff\">";
print"<td align=\"center\">";
print"$CompanyName";
print"</td>";
print"<td align=\"center\">";
print"$Post";
print"</td>";
print"<td align=\"center\">";
print"$salary";

print"</td>";
print"<td align=\"center\">";
print"$Branch";
print"</td>";
print"</tr>";
}
undef($query);
$dbh->disconnect;

print <<ENDHTML
</td>
</tr>
</table>
</form>
<table align="center" width=60% border=0>
<tr>
<td>
</td>
</tr>
<tr>
<td align="center">
<input type="button" value=" close "
onclick="javascript:history.back();">
</td>
</tr>
<tr>
<td>
</td>
</tr>
</table>
</table>
</td>
Page 16
ASP CODE
</tr>
</table>

</body>
</html>
ENDHTML

}
print "</p></body></html>";

sub decode
{
(%ha)=@_;
foreach $key(keys %ha)
{
$temp=$ha{$key};
$temp=~tr/+/ /;
$temp=~s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
$ha{$key}=$temp;
}
return %ha;
}

###################### ADD DATA INTO DATABASE ################################

<FORM name="AddForm" method ="post" action="http://localhost/bugs/AddComp.cgi"


OnLoad=setval() onSubmit="return check()">

#!c:/perl/bin/perl.exe
print "Content-Type:text/html\n\n";
use DBI;
$host = "localhost"; # your database server, can be localhost
$database = "consultancy"; # connecting database
$table = "Company"; # table within the database
$dbuser = "root"; # database login userid
$dbpass = ""; # database login password
$dbh=DBI->connect("dbi:mysql:dbname=consultancy","$dbuser","$dbpass");
print <<abc;
<html>
<body bgcolor=#fdfdfd>
<p>
abc
#print "Form request Method : $ENV{'REQUEST_METHOD'}\n";
if($ENV{'REQUEST_METHOD'}=~/GET/i)
{
# print "<p> $ENV{'QUERY_STRING'}</p>";
@values=split(/&/, $ENV{'QUERY_STRING'});
# print "<p>@values</p>";
foreach $namevalue(@values)
{
($key, $value)=split(/=/,$namevalue);
$namevalue = ~ tr/+/ /;
$hash{$key}=$value;
}
%hash=decode(%hash);
}
elsif($ENV{'REQUEST_METHOD'}=~ /^post$/i)
{
Page 17
ASP CODE
read(stdin,$buffer,$ENV{'CONTENT_LENGTH'});
@values=split(/&/, $buffer);

foreach $namevalue(@values)
{
($key, $value)=split(/=/,$namevalue);
$namevalue= ~ tr/+/ /;
$hash{$key}=$value;
}
%hash=decode(%hash);

$query="insert into Company


values('$hash{CompanyName}','$hash{Post}','$hash{salary}','$hash{Branch}')";
$dbh->do($query);
print"<br><br><br><br>";
print"<font size =5 color = black>";
print"<strong> <center> YOU HAVE SUCCESSFULLY ENTERED THE DATA";
print"<br><br>";
print"<a href='http://localhost/bugs/Adminmenu.html'> RETURN TO MAIN MENU
</A>";
print"</center></strong></font>";

}
print "</p></body></html>";

sub decode
{
(%ha)=@_;
foreach $key(keys %ha)
{
$temp=$ha{$key};
$temp=~tr/+/ /;
$temp=~s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
$ha{$key}=$temp;
}
return %ha;
}

###################### DELETE DATA FROM DATABASE ##########################

$query="delete from Company where companyname ='$var'";


$dbh->do($query);
################## UPLOAD CODE IN SERVLET
####################################
<a href="http://localhost:8080/servlet/upload1" TARGET="frame2">

######################## UPLOAD1.JAVA ##############################


import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
Page 18
ASP CODE
import java.io.*;
import java.util.*;

public class upload1 extends HttpServlet


{
public void doGet(HttpServletRequest req,HttpServletResponse res) throws
IOException,ServletException
{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
HttpSession session = req.getSession(true);

try
{
out.write("<html>\n");
out.write(" <head>\n");
out.write("<LINK href=\"1 (9).css\" type=text/css rel=\"stylesheet\">");
out.write(" <meta http-equiv=\"Content-Type\" content=\"text/html;
charset=UTF-8\">\n");
out.write(" <title>Universal Book Shop</title>\n");
out.write(" </head>\n");
out.write(" \n");
out.write(" \n");
out.write(" <BODY bgcolor=\"#fdfdfd\"> <FORM
ENCTYPE=\"multipart/form-data\" ACTION=\"http://localhost:8080/servlet/upload2\"
METHOD=POST>\n");
out.write("\t\t<br><br><br>\n");
out.write("\t <center><table border=\"2\" >\n");
out.write(" <tr><center><td colspan=\"2\"><p
align=\"center\"><B><font color=\"#black\"> UPLOADING THE
FILE</B><center></td></tr>\n");
out.write(" <tr><td><b><font color=\"#black\">Choose the
file To Upload:</b></td>\n");
out.write(" <td><INPUT NAME=\"F1\"
TYPE=\"file\"></td></tr>\n");
out.write("\t\t\t\t\t<tr><td colspan=\"2\"><p align=\"right\"><INPUT
TYPE=\"submit\" VALUE=\"Send File\" ></p></td></tr>\n");
out.write(" <table>\n");
out.write(" </center> \n");
out.write(" </FORM>\n");
out.write(" \n");
out.write(" \n");
out.write(" </body>\n");
out.write("</html>\n");
}
catch (Exception e)
{
}

}
}

############################ UPLOAD2.JAVA ##########################


import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
Page 19
ASP CODE
public class upload2 extends HttpServlet
{
public void doPost(HttpServletRequest req,HttpServletResponse res) throws
IOException,ServletException
{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
HttpSession session = req.getSession(true);

try {

out.write("\n");
out.write("\n");
out.write("\n");
out.write("\n");
out.write("<html>\n");
out.write(" <head>\n");
out.write(" <meta http-equiv=\"Content-Type\" content=\"text/html;
charset=UTF-8\">\n");
out.write(" <title>File upload</title>\n");
out.write(" </head>\n");
out.write(" <body bgcolor=\"#fdfdfd\">\n");
out.write("\n");
out.write(" <h1><font color=\"#black\">File Uploading...</h1>\n");
out.write(" ");
//to get the content type information from JSP Request Header
String contentType = req.getContentType();
//here we are checking the content type is not equal to Null and as well as the
passed data from mulitpart/form-data is greater than or equal to 0
if ((contentType != null) && (contentType.indexOf("multipart/form-data") >=
0))
{
DataInputStream in = new DataInputStream(req.getInputStream());
//we are taking the length of Content type data
int formDataLength = req.getContentLength();
byte dataBytes[] = new byte[formDataLength];
int byteRead = 0;
int totalBytesRead = 0;
//this loop converting the uploaded file into byte code
while (totalBytesRead < formDataLength)
{
byteRead = in.read(dataBytes, totalBytesRead,
formDataLength);
totalBytesRead += byteRead;
}
String file = new String(dataBytes);
//for saving the file name
String saveFile = file.substring(file.indexOf("filename=\"") + 10);
saveFile = saveFile.substring(0, saveFile.indexOf("\n"));
saveFile = saveFile.substring(saveFile.lastIndexOf("\\") +
1,saveFile.indexOf("\""));
int lastIndex = contentType.lastIndexOf("=");
String boundary = contentType.substring(lastIndex + 1,contentType.length());
int pos;
//extracting the index of file
pos = file.indexOf("filename=\"");
pos = file.indexOf("\n", pos) + 1;
pos = file.indexOf("\n", pos) + 1;
Page 20
ASP CODE
pos = file.indexOf("\n", pos) + 1;
int boundaryLocation = file.indexOf(boundary, pos) - 4;
int startPos = ((file.substring(0, pos)).getBytes()).length;
int endPos = ((file.substring(0, boundaryLocation)).getBytes()).length;
// creating a new file with the same name and writing the content in
new file
FileOutputStream fileOut = new FileOutputStream(saveFile);
fileOut.write(dataBytes, startPos, (endPos - startPos));
fileOut.flush();
fileOut.close();
out.write("<Br><table border=\"2\"><tr><td><b><font color=\"#black\">You have
successfully upload the file by the name of:</b>\n");
out.write("\t\t");
out.println(saveFile);
out.write("</td></tr></table> ");
}
out.write("\n");
out.write("\n");
out.write(" </body>\n");
out.write("</html>\n");
out.write("\n");
}
catch (Exception e)
{
}

}
}

########################### XML FILE SAVE AS .HTML EXTANSION


##################
<html>
<head>
<LINK HREF="CSS\1 (26).CSS" type="text/css" rel="stylesheet" >
<script type="text/javascript">
function parseXML()
{
text="<INFO>";
text=text+"<COMPANY>";

text=text+"<NAME>Microsoft</NAME>";
text=text+"<POST>Manager</POST>";
text=text+"<SALARY>50000</SALARY>";
text=text+"<BRANCH>Computer</BRANCH>";
text=text+"</COMPANY>";

text=text+"<COMPANY>";
text=text+"<NAME>Infosys</NAME>";
text=text+"<POST>Clerk</POST>";
Page 21
ASP CODE
text=text+"<SALARY>10000</SALARY>";

text=text+"<BRANCH>Electrical</BRANCH>";
text=text+"</COMPANY>";
text=text+"<COMPANY>";

text=text+"<NAME>GSFC</NAME>";
text=text+"<POST>Manager</POST>";

text=text+"<SALARY>25000</SALARY>";
text=text+"<BRANCH>Computer</BRANCH>";
text=text+"</COMPANY>";
text=text+"<COMPANY>";
text=text+"<NAME>ONGC</NAME>";

text=text+"<POST>Manager</POST>";
text=text+"<SALARY>35000</SALARY>";

text=text+"<BRANCH>Computer</BRANCH>";

text=text+"</COMPANY>";

text=text+"</INFO>";

try // Firefox, Mozilla, Opera, etc.


{
parser=new DOMParser();
xmlDoc=parser.parseFromString(text,"text/xml");
}
catch(e)
{
alert(e.message);
return;
}

document.getElementById("NAME1").innerHTML=
xmlDoc.getElementsByTagName("COMPANY")[0].getElementsByTagName("NAME")[0].childNodes
[0].nodeValue;
document.getElementById("POST1").innerHTML=
xmlDoc.getElementsByTagName("COMPANY")[0].getElementsByTagName("POST")[0].childNodes
[0].nodeValue;
document.getElementById("SALARY1").innerHTML=
xmlDoc.getElementsByTagName("COMPANY")[0].getElementsByTagName("SALARY")[0].childNod
es[0].nodeValue;
document.getElementById("BRANCH1").innerHTML=
xmlDoc.getElementsByTagName("COMPANY")[0].getElementsByTagName("BRANCH")[0].childNod
Page 22
ASP CODE
es[0].nodeValue;

document.getElementById("NAME2").innerHTML=
xmlDoc.getElementsByTagName("COMPANY")[1].getElementsByTagName("NAME")[0].childNodes
[0].nodeValue;
document.getElementById("POST2").innerHTML=
xmlDoc.getElementsByTagName("COMPANY")[1].getElementsByTagName("POST")[0].childNodes
[0].nodeValue;

document.getElementById("SALARY2").innerHTML=
xmlDoc.getElementsByTagName("COMPANY")[1].getElementsByTagName("SALARY")[0].childNod
es[0].nodeValue;
document.getElementById("BRANCH2").innerHTML=
xmlDoc.getElementsByTagName("COMPANY")[1].getElementsByTagName("BRANCH")[0].childNod
es[0].nodeValue;

document.getElementById("NAME3").innerHTML=
xmlDoc.getElementsByTagName("COMPANY")[2].getElementsByTagName("NAME")[0].childNodes
[0].nodeValue;

document.getElementById("POST3").innerHTML=
xmlDoc.getElementsByTagName("COMPANY")[2].getElementsByTagName("POST")[0].childNodes
[0].nodeValue;
document.getElementById("SALARY3").innerHTML=
xmlDoc.getElementsByTagName("COMPANY")[2].getElementsByTagName("SALARY")[0].childNod
es[0].nodeValue;
document.getElementById("BRANCH3").innerHTML=
xmlDoc.getElementsByTagName("COMPANY")[2].getElementsByTagName("BRANCH")[0].childNod
es[0].nodeValue;

document.getElementById("NAME4").innerHTML=
xmlDoc.getElementsByTagName("COMPANY")[3].getElementsByTagName("NAME")[0].childNodes
[0].nodeValue;
document.getElementById("POST4").innerHTML=
xmlDoc.getElementsByTagName("COMPANY")[3].getElementsByTagName("POST")[0].childNodes
[0].nodeValue;
document.getElementById("SALARY4").innerHTML=
xmlDoc.getElementsByTagName("COMPANY")[3].getElementsByTagName("SALARY")[0].childNod
es[0].nodeValue;
document.getElementById("BRANCH4").innerHTML=
xmlDoc.getElementsByTagName("COMPANY")[3].getElementsByTagName("BRANCH")[0].childNod
es[0].nodeValue;
}
</script>
</head>
<body onload="parseXML()">
Page 23
ASP CODE
<p>
<TABLE BORDER=1 BORDERCOLOR=BLUE ALIGN=CENTER>
<CAPTION>INFORMATION ABOUT COMPANIES </CAPTION>
<TR>
<TH>COMPANY NAME</TH> <TH>POST</TH>
<TH> SALARY </TH> <TH>BRANCH</TH>
<TR>

<TD>
<span id="NAME1"></span><br />
</TD>
<TD>
<span id="POST1"></span><br />
</TD>
<TD>
<span id="SALARY1"></span><br />
</TD>
<TD>
<span id="BRANCH1"></span><br />
</TD>

</TR>
<TR>
<TD>
<span id="NAME2"></span><br />
</TD>
<TD>
<span id="POST2"></span><br />
</TD>

<TD>
<span id="SALARY2"></span><br />
</TD>

<TD>
<span id="BRANCH2"></span><br />
</TD>
</TR>

</TR>
<TD>
</b> <span id="NAME3"></span><br />
</TD>
<TD>
<span id="POST3"></span><br />
</TD>
<TD>
<span id="SALARY3"></span><br />
Page 24
ASP CODE
</TD>
<TD>
<span id="BRANCH3"></span><br />
</TD>
</TR>
<TR>
<TD>
<span id="NAME4"></span><br />
</TD>

<TD>
<span id="POST4"></span><br />
</TD>
<TD>
<span id="SALARY4"></span><br />
</TD>

<TD>
<span id="BRANCH4"></span><br />
</TD>

</TR>
</p>
</body>
</html>
###################################### servlet admin valid code
##################################

<form name="formlogin" action="http://localhost:8080/servlet/admin" method="get"


OnLoad=setval() onSubmit="return check()">

import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class admin extends HttpServlet


{
public void doGet(HttpServletRequest req,HttpServletResponse res) throws
IOException,ServletException
{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
HttpSession session = req.getSession(true);
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
}
catch(Exception e)
{
}
Connection connection = null;
Statement statement = null;

Page 25
ASP CODE
try
{
String connectionURL =
"jdbc:mysql://localhost:3306/consultancy?user=root;password=root";
connection=DriverManager.getConnection(connectionURL);
}
catch(SQLException e)
{
out.println("Can't connect to database");
}
try
{
Statement smt=connection.createStatement();
String sql="SELECT * FROM admin";
String vusername=req.getParameter("username");
String vpassword=req.getParameter("password");
session.setAttribute("username",vusername);
session.setAttribute("password",vpassword);
ResultSet rs=smt.executeQuery(sql);
boolean flag=false;

while (rs.next())
{
String dusername = rs.getString("username");
String dpassword = rs.getString("password");
if ( vusername.equals(dusername) &&
vpassword.equals(dpassword) )
{
out.println("<html>");
out.println("<BODY
bgColor=#fdfdfd>");
out.println("<p><p><p>");
out.println("<META
HTTP-EQUIV=\"refresh\";
content=\"2;url=http://localhost:8080/bugs_servlet/Adminmenu.html\">");
out.println("<center><h1>Login
Successful !</h1>");
out.println("</center>");
out.println("</body></HTML>");

flag=true;
break;
}
}
if(!flag)
{
out.println("<html>");
out.println("<BODY bgColor=#fdfdfd>");
out.println("<p><p><p>");
out.println("<META HTTP-EQUIV=\"refresh\";
content=\"2;url=http://localhost:8080/bugs_servlet/Administrator.html\">");
out.println("<center><h1>Login Unsuccessful
!</h1>");
out.println("</center>");
out.println("</body></HTML>");
}
}
catch (Exception e)
Page 26
ASP CODE
{
out.println("some error");
}
try
{
connection.close();
}
catch(SQLException e)
{
out.println("Can't Dis-connect from database");
}
}
}

Page 27

Вам также может понравиться