Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DB rec gets written-but contains no data from the form 2

Status
Not open for further replies.

JohnBates

MIS
Feb 27, 2000
1,995
US
Hi ASP gurus -

Problem: What the user enters into the Form is not getting placed into the table record.

Thanks for any suggestions.
John


ASP # 1 Input Form
This is some of the code in the ASP that accepts user input:

<FORM ACTION=&quot;ISSystemsAccessVerify.ASP&quot; NAME=&quot;frmReq&quot; METHOD=&quot;POST&quot;
onSubmit=&quot;return ValidateInput()&quot;>

Please enter your First Name
<INPUT TYPE=TEXT NAME=&quot;NameFirst&quot; Size=&quot;15&quot; Maxlength=&quot;15&quot;>




This is the ASP that writes the database record... but what
the user entered into the Form is not getting placed into
the record.

ASP # 2 Add DB record

<!--#include file=&quot;ISSystemsAccessConnect.asp&quot;-->

<%
Dim sql
Dim strNameLast

strNameLast = Request.Form(&quot;NameLast&quot;)

sql = &quot;INSERT INTO SystemsAccessReqs (UserNameL) VALUES ('&quot; & strNameLast & &quot;');&quot;

conn.execute sql
%>









 
TechnicalAnalysis - Thanks for replying.

I do not get any error messages.

SystemAccessReqs is my SQL Server table and UserNameL is a field in that table.

strNameLast = Request.Form(&quot;NameLast&quot;) should be retrieving what the user entered into the NameLast text box and store it in strNameLast..... but after the record is written (the connection and the Insert work OK), all the fields (except for those that have a default value) are empty/blank.

(For this example, I trimmed the code alot and in my haste mixed up NameFirst and NameLast... but in the ASP it is not like that).

Hope I have explained it well enough.
Thanks, John


 
It's hard to help without complete code, but from what you've posted, one could notice some problems with the code.
That's what you have in your form:

<INPUT TYPE=TEXT NAME=&quot;[red]NameFirst[/red]&quot; Size=&quot;15&quot; Maxlength=&quot;15&quot;>


And here's what you trying to insert:

strNameLast = Request.Form(&quot;[red]NameLast[/red]&quot;)

sql = &quot;INSERT INTO SystemsAccessReqs (UserNameL) VALUES ('&quot; & strNameLast & &quot;');&quot;


So the name of the textbox (say, NameFirst) on a form must correspond to the contents of double quotes in Request.Form(&quot;name_of_the_control_on_form&quot;) expression. In this case it has to be Request.Form(&quot;NameFirst&quot;)
 
I guess it would be easier to help you if you showed us some code, as well as what actually does get inserted in the db... This is not a bug - it's an undocumented feature...
;-)
 
Thanks guestg and Jonax - The textbox name and Request.Form name do match as you will see below..... someone asked to see the code (trimmed out some of the non-essential variables to shorten it abit)

Thanks for your time. John



The First ASP that drives the Form Input:

<FORM ACTION=&quot;ISSystemsAccessVerify.ASP&quot; NAME=&quot;frmReq&quot; METHOD=&quot;POST&quot; onSubmit=&quot;return ValidateInput()&quot;>

Please enter your First Name
<INPUT TYPE=TEXT NAME=&quot;NameFirst&quot; Size=&quot;15&quot; Maxlength=&quot;15&quot;>
Middle Initial
<INPUT TYPE=TEXT NAME=&quot;NameMI&quot; Size=&quot;1&quot; Maxlength=&quot;1&quot;>
Last Name
<INPUT TYPE=TEXT NAME=&quot;NameLast&quot; Size=&quot;20&quot; Maxlength=&quot;20&quot;>
<BR>
Work Phone #
<INPUT TYPE=TEXT NAME=&quot;PhoneW&quot; Value=&quot;615&quot; Size=&quot;10&quot; Maxlength=&quot;10&quot;>
Home Phone #
<INPUT TYPE=TEXT NAME=&quot;PhoneH&quot; Value=&quot;615&quot; Size=&quot;10&quot; Maxlength=&quot;10&quot;>
<BR>
Fax Phone # <INPUT TYPE=TEXT NAME=&quot;PhoneFax&quot; Value=&quot;615&quot; Size=&quot;10&quot; Maxlength=&quot;10&quot;>
Dept. #
<INPUT TYPE=TEXT NAME=&quot;Dept&quot; Size=&quot;6&quot; Maxlength=&quot;6&quot;>
<BR>
Job Title / Description
<INPUT TYPE=TEXT NAME=&quot;JobTitle&quot; Size=&quot;35&quot; Maxlength=&quot;35&quot;>
<BR>

<div Style=&quot;border:1px solid #000000;&quot;>
<H3><B>SERVICES REQUESTED: </B></H3>
<PRE><B> (Check all that apply)</B>

<INPUT TYPE=CHECKBOX NAME=&quot;NEWWS&quot;> New workstation(need signed requisition) <INPUT TYPE=CHECKBOX NAME=&quot;EXWS&quot;> Existing workstation
<INPUT TYPE=CHECKBOX NAME=&quot;NEWUSER&quot;> New user <INPUT TYPE=CHECKBOX NAME=&quot;EXUSER&quot;> Existing user
<BR>
AS/400 access: <INPUT TYPE=CHECKBOX NAME=&quot;MARCAM&quot;> <B>MARCAM</B> <INPUT TYPE=CHECKBOX NAME=&quot;JDE&quot;> <B>JDE</B> <INPUT TYPE=CHECKBOX NAME=&quot;WMS&quot;> <B>WMS</B> <INPUT TYPE=CHECKBOX NAME=&quot;PR&quot;> <B>Payroll</B> <INPUT TYPE=CHECKBOX NAME=&quot;TA&quot;> <B>Time & Attendance</B>
Optional: Make AS/400 sign on profile similar to: <INPUT TYPE=TEXT NAME=&quot;ModelAS400&quot; Size=&quot;25&quot; Maxlength=&quot;25&quot;>
<BR>
Network access: <INPUT TYPE=CHECKBOX NAME=&quot;NT&quot;> <B>Windows NT account</B> <INPUT TYPE=CHECKBOX NAME=&quot;LNOTES&quot;> <B>Lotus Notes</B> Groups:SG- <INPUT TYPE=TEXT NAME=&quot;LNOTESGROUP&quot; Size=&quot;20&quot; Maxlength=&quot;20&quot;>
Optional: Make NT sign on profile similar to: <INPUT TYPE=TEXT NAME=&quot;ModelNT&quot; Size=&quot;25&quot; Maxlength=&quot;25&quot;>
<BR>
<INPUT TYPE=CHECKBOX NAME=&quot;CLASER&quot;><B> Color Laser Printer</B> <INPUT TYPE=CHECKBOX NAME=&quot;NTROAM&quot;><B> Windows NT roaming profile</B>
<BR>
Remote access: <INPUT TYPE=CHECKBOX NAME=&quot;DIALUP&quot;> <B>Dial-up Access</B> <INPUT TYPE=CHECKBOX NAME=&quot;MODEM&quot;> <B>Install Modem</B>
<BR>
<FONT size=&quot;2&quot;><B> * Use the space below to request additional services or to provide explanation / justification for this request:
</FONT></B>
<INPUT TYPE=TEXT NAME=&quot;SRCOMMENTS&quot; Size=&quot;135&quot; Maxlength=&quot;135&quot;>
</PRE>

<BR>

<TABLE>
<TR>
<TD width=&quot;100%&quot; align=&quot;LEFT&quot;>
<INPUT TYPE=&quot;SUBMIT&quot; value=&quot;PROCEED TO NEXT STEP&quot;>
</TD>

<TD align=&quot;RIGHT&quot;>
<INPUT TYPE=&quot;RESET&quot; value=&quot;Clear Form&quot;>
</TD>
</TR>
</TABLE>

</div>
</div>
</div>
</FORM>
</BODY>
</HTML>

And the 2nd ASP that writes to the Table:

<!--#include file=&quot;ISSystemsAccessConnect.asp&quot;-->


<%
Dim sql
Dim strNameLast, strNameFirst, strNameMI, strPhoneW, strPhoneH, strPhoneFax
Dim intDept, strJobTitle, datCurDate
Dim blnNewWS, blnExWS, blnNewUser, blnExUser, blnMarcam, blnJDE, blnWMS
Dim blnPR, blnTA, blnNT, blnNTRoam, blnLNotes, blnCLaser, blnDialUp, blnModem
Dim strModelAS400, strModelNT, strLNotesGroup, strSRComments



strNameLast = Request.Form(&quot;NameLast&quot;)
strNameFirst = Request.Form(&quot;NameFirst&quot;)
strNameMI = Request.Form(&quot;NameMI&quot;)
strPhoneW = Request.Form(&quot;PhoneW&quot;)
strPhoneH = Request.Form(&quot;PhoneH&quot;)
strPhoneFax = Request.Form(&quot;PhoneFax&quot;)
intDept = Request.Form(&quot;Dept&quot;)
strJobTitle = Request.Form(&quot;JobTitle&quot;)

sql = &quot;INSERT INTO SystemsAccessReqs (UserNameL, UserNameF, UserNameMI, UserPhoneW, UserPhoneH, UserFax, Dept#, JobTitle, NewWS, ExistingWS, NewUser, ExistingUser, Marcam, JDE, WMS, Payroll, TA, NT, NTRoaming, LNotes, ColorLaser, DialUpAccess, Modem, LNotesGroup, ModelAS400Profile, ModelNTProfile, SerReqComments, DateSubmitted) VALUES ('&quot; & strNameLast & &quot;', '&quot; & strNameFirst & &quot;', '&quot; & strNameMI & &quot;', '&quot; & strPhoneW & &quot;', '&quot; & strPhoneH & &quot;', '&quot; & strPhoneFax & &quot;', '&quot; & intDept & &quot;', '&quot; & strJobTitle & &quot;', '&quot; & blnNewWS & &quot;', '&quot; & blnExWS & &quot;', '&quot; & blnNewUser & &quot;', '&quot; & blnExUser & &quot;', '&quot; & blnMarcam & &quot;', '&quot; & blnJDE & &quot;', '&quot; & blnWMS & &quot;', '&quot; & blnPR & &quot;', '&quot; & blnTA & &quot;', '&quot; & blnNT & &quot;', '&quot; & blnNTRoam & &quot;', '&quot; & blnLNotes & &quot;', '&quot; & blnCLaser & &quot;', '&quot; & blnDialUp & &quot;', '&quot; & blnModem & &quot;', '&quot; & strModelAS400 & &quot;', '&quot; & strModelNT & &quot;', '&quot; & strLNotesGroup & &quot;', '&quot; & strSRComments & &quot;', &quot; & datCurDate & &quot;);&quot;

conn.execute sql
%>

 
in the asp script that writes to the table, do you do any kind of validation that the form was actually submitted, and/or can you do a response.write of some of the form fields to show that they have values when they get to that asp script?

ie:
response.write strNameLast & &quot; &quot; & strNameFirst & &quot; &quot; & strNameMI & &quot; &quot; & strPhoneW & &quot; &quot; & strPhoneH & &quot; &quot; & strPhoneFax & &quot; &quot; & intDept & &quot; &quot; & strJobTitle
 
or try Response.write sql just before conn.execute sql may kick up an error but it will tell you exactly what is trying to insert Live long and make your kids suffer..
 


johnbates,

I believe the problem may be in you function &quot;validateInput&quot;. Can you show us that function?

Thanks,
fengshui_1998
 
Thanks Cheech and fengshui_1998 !

here is the Validate function...
<SCRIPT language=&quot;JavaScript&quot;>
<!--
function ValidateInput()
{

if (document.frmUser.NameFirst.value ==&quot;&quot; ||
document.frmUser.NameLast.value ==&quot;&quot;)

{
alert (&quot;Your first name or your last name is blank&quot;);
return false;
}
else
return true;
}
-->
</SCRIPT>



Cheech - When I added the Response.Write sql...... get

VALUES ('', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 12/11/01);

so obviously I'm not doing what is necessary to pick up what was entered on the form.

Thanks - you guys sure have alot of patience! John

 


johnbates,

Try this.

<SCRIPT language=&quot;JavaScript&quot;>
<!--
function ValidateInput()
{
if (document.frmUser.NameFirst.value ==&quot;&quot; ||
document.frmUser.NameLast.value ==&quot;&quot;)
{
alert (&quot;Your first name or your last name is blank&quot;);
return false;
}
else
document.forms.frmReq.submit();
}
-->
</SCRIPT>

fengshui_1998


 


johnbates,

I also noticed that the name of your form is &quot;frmReq&quot; but you refer to it as &quot;frmUser&quot; in you javascript code.

fengshui_1998
 
fengshui - Yes, I have tried it using the same form name, still get blank fields in record.....

I failed to detial the &quot;middle&quot; layer of code, which is the ASP that actually calls the ISSystemsAccesWrite.ASP...if the user clicks Submit:

<%@ Language=VBScript %>

<HTML>
<HEAD>
<TITLE>IS Systems Access Response</TITLE>
<!--mstheme--><link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;../_themes/glacier-sg/glac1011.css&quot;><meta name=&quot;Microsoft Theme&quot; content=&quot;glacier-sg 1011, default&quot;>
</HEAD>
</HEAD>

<BODY>
<div Style=&quot;border:1px solid #000000;&quot;>
<H3 align=&quot;CENTER&quot;><B>INFORMATION SYSTEMS - EHP SPRINGFIELD<BR>
<B>Systems Access and Change Request</B><BR>
<B>Please Review the Information - Click SUBMIT - Or Click BACK If You Need To Make Corrections</H3></B>
<FORM ACTION=&quot;ISSystemsAccessWrite.ASP&quot; METHOD=&quot;POST&quot;>


<%
Response.Write &quot;Total # of values received = &quot;
Response.Write Request.Form.Count & &quot;<BR>&quot;


Response.Write Request.Form(&quot;NameFirst&quot;) & &quot; &quot;
Response.Write Request.Form(&quot;NameLast&quot;) & &quot;<BR>&quot;
Response.Write &quot;Dept: &quot; & &quot; &quot;
Response.Write Request.Form(&quot;Dept&quot;) & &quot;<BR>&quot;
Response.Write &quot;Phone: &quot; & &quot; &quot;
Response.Write Request.Form(&quot;PhoneW&quot;) & &quot;<BR>&quot;
Response.Write &quot;Job Title: &quot; & &quot; &quot;
Response.Write Request.Form(&quot;JobTitle&quot;) & &quot;<BR>&quot;
%>

<TABLE>
<TR>
<TD width=&quot;100%&quot; align=&quot;CENTER&quot;>
<INPUT TYPE=&quot;SUBMIT&quot; value=&quot;Submit Request To IS Dept&quot;>
</TD>
</TR>
</TABLE>
</div>
</FORM>
</BODY>
</HTML>

**IMPORTANT** On this &quot;middle&quot; form... the entered values
ARE displayed as entered.... so I guess I have a disconnect between the middle form and the third ASP which performs the write. I'm sure the problem is something very simple.
I'm a newbie at Web development.

Thanks, John
 
what is your form action=? if it's not the asp script that is writing to the database, then you have to store your form input fields somehow to forward them on. otherwise, they are lost by the time you get to that asp script.

from what you just said, it sounds like you go to the script you just posted, then from that you go to the script that writes to the db. which means you lost your form input.

you either need to make the above script an include file or subroutine, or forward the form variables to the final asp script somehow.

if that's the case, let us know, if you need more help, we can direct you there.
 
johnbates,

I agree with lobstah and one of your forms has no name declared. You will need it if your are doing client-side validation.

<FORM ACTION=&quot;ISSystemsAccessWrite.ASP&quot; METHOD=&quot;POST&quot; name=????>

fengshui_1998

 
You guys have identified the problem....

As I see it, I could store the form variables by using the Session object or by using cookies.

In theory would this work:
Lets say I start a session in ASP1, setting an appropriate timeout value.

In ASP2 (the Verify.ASP where the user can back-out or submit to write the record) save the input variables...
Session(&quot;NameL&quot;) = Request.Form(&quot;NameLast&quot;)

Then in ASP3....
strNameLast = Session(&quot;NameL&quot;)

Would strLastName now contain what the user entered into the form?

Is this a reasonable way to save the input form's values
or is it overly complex?

Thanks, John






 
johnbates,


You can also store values in &quot;hidden&quot; boxes.

<input type=&quot;hidden&quot; name=&quot;NameFirst&quot; value=&quot;<%=strNameFirst&quot;>

The values will be passed on to the next ASP page when the user submits his form. Treat it as if it was actually on the ASP/WEB page, but the web client never sees it.

fengshui_1998
 
or you could make ISSystemsAccesWrite.ASP an include file in the &quot;middle form&quot;, making it a subroutine or function that you call from the &quot;middle form&quot;, in which case the form input variables will be available to ISSystemsAccesWrite.ASP.

it's when you transfer processing to a new page, either with a redirect, a hyperlink, a form action, or the like, that you lose your form data.

i would opt for using an include file. using session variables or cookies could get ugly......
 
Thanks fengshui_1998 and Lobstah -

For now, to keep it simple enough for me to understand,
I'm using the &quot;hidden&quot; box technique (I've used this technique in other programming languages).

The few fields I'm using hidden on now are getting written to the record...... if the hidden trick also works
for bit/boolean data types then I'm set.

Lobstah, I will experiment with the include file later; I think it is the better technique.

Thanks very much for your time. John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top