Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

insert data with ASP to oracle using form

Posted on 2004-04-12
3
Medium Priority
?
668 Views
Last Modified: 2011-10-03
HI ALL

ineed the code for insert data to oracle database by using ASP form and HTMl

i'm using this code for reading data from my database


<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 1</title>
</head>

<body>
personal_ino
<%
        Set OraDatabase = Server.CreateObject("ADODB.Connection")
        OraDatabase.ConnectionString= "provider=MSDAORA.1;Data source=alm;user id=s019699;password=s019699;"
        OraDatabase.open
        Set osRecordSet = OraDatabase.Execute("SELECT FIRST_NAME from personal_info")
      

        while not osRecordSet.EOF
             response.write osRecordSet("FIRST_NAME") & "<br>"
             osRecordSet.moveNext
          wend

        
        osRecordSet.Close
        OraDatabase.Close
      %>
</body>

</html>


how can ifix this code or how can i write now code for insert data by form

thanx for helping

regards




0
Comment
Question by:moon_face
  • 2
3 Comments
 
LVL 54

Accepted Solution

by:
Ryan Chong earned 2000 total points
ID: 10806664
Here is an example on Insert data into database using ASP:

Test.asp:

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<script language="javascript">
      function validate(frm) {
            //Add your validation here..
            return true;
      }
</script>
<body bgcolor="#FFFFFF" text="#000000">
<form name="form1" method="post" action="processinsert.asp" onsubmit="return validation(this)">
  <table border="0" width="98%">
    <tr>
      <td width="30%" height="19" valign="top"><b>Value 1:</b></td>
      <td width="70%" height="19">
        <input type="text" name="value1" size="50" maxlength="255">
      </td>
    </tr>
    <tr>
      <td width="30%" height="19" valign="top">&nbsp; </td>
      <td width="70%" height="19" align="center">
        <div align="left">
          <p>
            <input type="submit"
          value="Submit" name="B2">
            <input type="reset" value="Reset" name="B1">
        </div>
      </td>
    </tr>
  </table>
</form>
</body>
</html>

processinsert.asp:

<%
      Response.expires = 0
      response.expiresabsolute = Now() - 1
      response.addHeader "pragma","no-cache"
      response.addHeader "cache-control","private"
      Response.CacheControl = "no-cache"
%>
<%
      dbConnectUser = "username"
      dbConnectPwd = "password"
      sid = "sid"
      user =  ""
      set conn=server.CreateObject("adodb.connection")
      conn.open "Provider=MSDASQL;DRIVER={Microsoft ODBC for ORACLE};UID=" & dbConnectUser &";PWD=" & dbConnectPwd & ";Server=" & sid

%>
<%
      Set Rs=Server.CreateObject("ADODB.Recordset")
      
      value1= Replace(request("value1"),"'","''")
            
      SQLStr = "Insert into tblTest (" & _
                   "value1 ) values ( " & _
                   "'" & value1 & "' " & _
                   ")"
      conn.execute SQLStr
      
      Conn.close
      Set Rs=Nothing
      Set Conn=Nothing

               //Redirect to thank you page if necessary
             response.redirect "thnkyou.asp"
%>

For more info on Oracle ConnectionString, see:

http://www.connectionstrings.com
http://www.able-consulting.com/ADO_Conn.htm

then look for Oracle..

Hope this helps
0
 

Author Comment

by:moon_face
ID: 10811297
thanx for ur aswer and i tried to work with it in my data base but ihave proplem with this lines

__________________________________


     value1= Replace(request("value1"),"'","''")
 
         
     SQLstr= "Insert into tblTest(value1)values("'"& value1 &"'")"
               
     conn.execute SQLStr
__________________________________

and idon't what the problem ,,, icreated tblTest table with value1 field

 create table tblTest
 (value1 varchar2(15) not null,
 constraint value1 primary key(value1));

and i modify the code according to my database as :

<%
     Response.expires = 0
     response.expiresabsolute = Now() - 1
     response.addHeader "pragma","no-cache"
     response.addHeader "cache-control","private"
     Response.CacheControl = "no-cache"
%>
<%
     Set OraDatabase = Server.CreateObject("ADODB.Connection")
       OraDatabase.ConnectionString= "provider=MSDAORA.1;Data source=alm;user

id=s019699;password=s019699;"
       OraDatabase.open

%>
<%

     
     Set Rs=Server.CreateObject("ADODB.Recordset")
     
     value1= Replace(request("value1"),"'","''")
 
         
     SQLstr= "Insert into tblTest(value1)values("'"& value1 &"'")"
               
     conn.execute SQLStr
     
     
     Conn.close
     Set Rs=Nothing
     Set Conn=Nothing


//Redirect to thank you page if necessary

             response.redirect "thnkyou.asp"
%>

unfortinatly igot this error

Error Type:
Microsoft VBScript runtime (0x800A01A8)
Object required: 'conn'
/processinsert.asp, line 24

thanx for ur cooperate



0
 

Author Comment

by:moon_face
ID: 10811836
thanx it works with me

thanx for help
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

963 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question