Current location: Hot Scripts Forums » Programming Languages » ASP » i storing data in mssql through asp process file


i storing data in mssql through asp process file

Reply
  #1 (permalink)  
Old 06-22-06, 06:52 AM
traceMe traceMe is offline
Newbie Coder
 
Join Date: Oct 2003
Location: india(mumbai)
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
i storing data in mssql through asp process file

I have written this piece of code to enter the data in the database that is filled by the user but its entering double time in the database my database is ms sql2000 its sql code looks like this

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[enq_frm_data]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[enq_frm_data]
GO

CREATE TABLE [dbo].[enq_frm_data] (
[srno] [int] IDENTITY (1, 1) NOT NULL ,
[name] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[email] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[phno] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[qua] [varchar] (4000) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[exp] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[createdon] [datetime] NULL
) ON [PRIMARY]
GO

and my asp code looks like this

<!--#include file="connection.asp"-->
<%dim rsenq
set rsenq=server.createobject("adodb.recordset")
rsenq.open "select * from enq_frm_data",objConn,0,2
rsenq.addnew
rsenq("name")=request("realname")
rsenq("email")=request("Email")
rsenq("phno")=request("phoneNo")
rsenq("qua")=request("Qualification")
if not request("experience")="" then
rsenq("exp")=request("experience")
end if
rsenq("createdon")=now
rsenq.update
rsenq.close
set rsenq=nothing
response.write request("realname")&","&request("Email")&","&reque st("phoneNo")&","&request("Qualification")&","&req uest("experience")
response.redirect "enquiry_thanks.asp"
%>

kindly help if there is any mistake that iam making this snippet has worked fine in my earlier code's but dont understand y its behaving like this....


regards,
Praveenraj
Reply With Quote
  #2 (permalink)  
Old 06-29-06, 08:14 AM
GO4TF4CE's Avatar
GO4TF4CE GO4TF4CE is offline
Wannabe Coder
 
Join Date: Apr 2004
Posts: 223
Thanks: 0
Thanked 0 Times in 0 Posts
Talking

personally I would insert the info like this as its easier to see any problems.
Code:
'prevents SQL injection
Function fixquotes( byVal theString )
	fixquotes = Replace( theString, "'", "''" )
End Function

name=fixquotes(request("realname"))
email=fixquotes(request("Email"))
phno=fixquotes(request("phoneNo"))
qua=fixquotes(request("Qualification"))
exp=fixquotes(request("experience"))

SQL1=SQL1 & "name,"
SQL2=SQL2 & "'" & name & "',"

SQL1=SQL1 & "email,"
SQL2=SQL2 & "'" & email & "',"

SQL1=SQL1 & "phno,"
SQL2=SQL2 & "'" & phoneNo & "',"

SQL1=SQL1 & "qua,"
SQL2=SQL2 & "'" & Qualification & "',"

if experience <> "" then
SQL1=SQL1 & "exp,"
SQL2=SQL2 & "'" & experience& "',"
end if

'get the date from the sql server and not the webserver, solves some date issues normally.
SQL1=SQL1 & "createdon"
SQL2=SQL2 & "GETDATE()"

objConn.execute("INSERT INTO enq_frm_data(" & SQL1 & ") VALUES(" & SQL2 & ")")
hope this helps, if there is still a problem then drop the table and recreate it using the standard design mode and not using the script.

let us know how you get on.
__________________
Intelligence is not knowledge, but the way we use our knowledge.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to retrieve data from excel file to ASP page? lymni22 ASP 8 12-13-07 08:11 PM
ASP upload prob minority ASP 1 06-27-05 08:35 AM
write to beginning of file or reverse an array of binary data abtimoteo Perl 1 01-20-04 10:09 AM
Upload file to table so ONLY files tied to primary key are displayed in record? grafixDummy PHP 4 12-20-03 04:28 PM


All times are GMT -5. The time now is 03:48 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.