Solved

ASP AND SQL SERVER (Problem in inserting a record)

Posted on 2003-11-10
9
483 Views
Last Modified: 2008-03-06
When users register themselves on my website, i encountered a weird problem, when they finished filling up the forms and insert a new record, the record of fields on the last asp page(e.g. combo box, textbox) is "1000, 1000" when the value should be only "1000". That mean it append the result again, why is this so? On these last asp page before i execute the insert sql, there are some hidden fields where the value is passed from the previous asp page these hidden fields do not have value error while those visible field have value appended. Below are the brief section of my coding.

<!--E.G. VISIBLE FIELDS-->
<input type=text name="Expected_Pay" align="right" size="8" maxlength="8" style="background-color:#ffffff">Per Month
<!--E.G. HIDDEN FIELDS-->
<input type="hidden" name="EmailAddress" value="<%= Request.Form("EmailAddress")%>">
<input type="hidden" name="Password" value="<%= Request.Form("Password")%>">

<!--MY INSERT SQL-->
<%
Option Explicit
Response.Buffer = "true"

Dim objUpload
Set objUpload = server.createobject("ASPUpLoad.clsUpload")

Function StrQuoteReplace(strValue)
  If strValue <> "" And Not IsNull(StrValue) Then
  StrQuoteReplace = Replace(strValue, "'", "''")
  End If
End Function

addSQL = "INSERT INTO WebCandidate(EmailAddress, Password, Expected_Pay)" & "VALUES( '" & StrQuoteReplace(objUpload.Form("EmailAddress")) &  "', '" &  StrQuoteReplace(objUpload.Form("Password")) & "', '"  & StrQuoteReplace(objUpload.Form("Expected_Pay")) & "')"
objConn.Execute(addSQL)
%>

NOTE!!!: I notice that only a small pool of users' record(maybe 1 out of 100) got this problem that rest of the records inserted are fine. It should not be programming error else i believe all the records should also have values appended. The weird thing is that only visible field has value appended and not those hidden fields... Pls help, thank in advance
0
Comment
Question by:Owen10
9 Comments
 
LVL 29

Expert Comment

by:David H.H.Lee
Comment Utility
Owen10,
>>...The weird thing is that only visible field has value appended and not those hidden fields...
-you can try this, maybe help to solve your problems :
Instead of
<input type="hidden" name="EmailAddress" value="<%= Request.Form("EmailAddress")%>">
<input type="hidden" name="Password" value="<%= Request.Form("Password")%>">

Change to
<input type="text" name="EmailAddress" style="visibility:hidden" value="<%= Request("EmailAddress")%>">
<input type="text" name="Password" style="visibility:hidden" value="<%= Request("Password")%>">

Regards
x_com
0
 

Author Comment

by:Owen10
Comment Utility
The problem does not lies in the hidden fields as the values in those hidden fields are inserted correctly. those values that user key-in in the last page(fields that are visible) before the whole information process that come out with double value(e.g. 100, 100)

Thanks,
Owen
0
 
LVL 10

Expert Comment

by:D_M_D
Comment Utility
Try changing your sql statement to the below:

addSQL = "INSERT INTO WebCandidate(EmailAddress, Password, Expected_Pay)" & "VALUES( '" & StrQuoteReplace(objUpload.Form("EmailAddress")) &  "', '" &  StrQuoteReplace(objUpload.Form("Password")) & "', '"  & StrQuoteReplace(Request.Form("Expected_Pay")) & "')"
objConn.Execute(addSQL)

--------
D_M_D
0
 
LVL 1

Expert Comment

by:butcherd11
Comment Utility
I would say that this would cause you another issue.

Having used the clsUpload object before... it won't allow you to use Request.Form, Request.QueryString, or TRIM(request("")) with it's object. If you take a step back for a minute and just separate these out...

I did notice a syntax error in that last querystring ... so have amended below. Try this and let me know how you get on with this.

addSQL = "INSERT INTO WebCandidate(EmailAddress, Password, Expected_Pay)" &_
addSQL = addSQL & "VALUES( '" & StrQuoteReplace(objUpload.Form("EmailAddress")) &  "', '" &  StrQuoteReplace(objUpload.Form("Password")) & "', '"  & StrQuoteReplace(Request.Form("Expected_Pay")) & "')"

objConn.Execute(addSQL)


Another thing it might be of course, is that somehow there is two instances of the same field within the form.

<input type="hidden" name="fieldname" value="theValue">
<input type="hidden" name="fieldname" value="theValue">

If thats the case and two fields are the same, then it will append one to the other as it passes through the querystring. so you'll end up with ("1000,1000") All the same one worth checking out.

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:Owen10
Comment Utility
DMD: Wat is the diffenence between ur Sql and my Sql?

butcherd11:My Sql shouldn't have any error because most of the user could add probably as i have mentioned. and y is the "expected_pay" the only field using request.form which i believe won't work with clsUpload? I got no duplicate value in different field. as i say again. most of the recorded added are correct except for a few of the users(1 out of 100) which has this problem.

With Regards,
Owen
0
 
LVL 1

Expert Comment

by:butcherd11
Comment Utility
Owen,

Apologies.... yesterday was a bad day for me.. i kinda of missed the issue a little bit.

You are of course right, the syntax is correct, after looking again ... i do know though as specified above, the request.form shouldn't work anyway with the objUpload.Form, as it has conflicts with the different methods of request being used at the same time. ( so the top statement is correct. )

Is it only the expected pay field that it does this for ?

I've done a test by printing out aswell as inserting to the database as a test, and looping through to simulate your 100 times... and can't replicate this.
0
 

Author Comment

by:Owen10
Comment Utility
butcherd11,

Every1 has his day, bro...i having quite a few bad ones recently...

The scenario is this...there are a few registration pages(ASP), so from one page to another i would use request.form to pass in the value to a hidden field..
E.G.
<input type="hidden" name="EmailAddress" value="<%= Request.Form("EmailAddress")%>">
<input type="hidden" name="Password" value="<%= Request.Form("Password")%>">
So on the last page of the registration, i already have quite a few hidden fields...there is still quite a few fields still to be complete on the last page. If the duplication occurs, it occurs to all the fields of the last page, be it combo or text and NOT those hidden fields that is also on the last page. Weird rite bro! how come hidden fields are not affected, maybe the values are pass-in using request.form to the hidden fields.

this error occur on 2 websites that i have because the styles are the same. The error occurs sort of ramdomise...i was thinking if it could be the users' coms that generate the error. Any idea?. BTW issit illegal to post our email here? so i can actually send u the coding that i have...

With Regards,
Owen
0
 
LVL 1

Accepted Solution

by:
butcherd11 earned 100 total points
Comment Utility
Just in case i'l split the email address up...

it's "butcherd" ...   Having tried something different to what i had originally tried, the only way i could force an appended query "100,100" was to have the form field called the same thing twice. second part of addy "@interleasing.co.uk"

Speak later dude.

Dave ;)
0
 

Author Comment

by:Owen10
Comment Utility
butcher:
Tat's for the effort thou the problem is still not solved...thanks
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now