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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Could somebody have a look at this

Status
Not open for further replies.

finnoscar

Technical User
Aug 17, 2002
55
0
0
GB
Could somebody have a look at this and tell me what if anything is missing from it:

<%@ LANGUAGE = JavaScript%>
<HTML>
<HEAD>
<meta name=&quot;Microsoft Theme&quot; content=&quot;indust 110, default&quot;>
</HEAD>
<BODY>
<%


// Connect to database
var adoConnection = Server.CreateObject(&quot;ADODB.Connection&quot;);
adoConnection.Open(&quot;DSN=DogDSN&quot;);
var adoRecordset;

// Create SQL to update pups info in Breeders table
var mySQL = &quot;UPDATE Breeders SET PupsAvailable ='&quot; & Request.Form(&quot;txtPupsAvailable&quot;)&&quot;'&quot;
& &quot;WHERE BreederNo =&quot;Val(Request.Form(&quot;txtBreederNo&quot;));


// Execute SQL to update breeder pups info
adoConnection.Execute(mySQL);


// Recordset not needed after this so close it and allow release of memory
adoRecordset.Close();
adoRecordset = null;



Response.Write(&quot;<H2><CENTER>Your Details have been updated successfully&quot; +
&quot;</CENTER></H2>&quot;);
%>
</BODY>
</HTML>
 
there's a ' missing in the SQL
var mySQL = &quot;UPDATE Breeders SET PupsAvailable ='&quot; & Request.Form(&quot;txtPupsAvailable&quot;)&&quot;'&quot;
& &quot;WHERE BreederNo =&quot;Val(Request.Form(&quot;txtBreederNo&quot;)&quot;; hope I helped!
[roll2]
admin@onpntwebdesigns.com
 
I get a missing & at &quot; WHERE BreederNo =&quot; & Val(Request.Form(&quot;txtBreederNo&quot;)), and you'll want to put a space before WHERE

so it should look like
Code:
mySQL = &quot;UPDATE Breeders SET PupsAvailable ='&quot; &  Request.Form(&quot;txtPupsAvailable&quot;) & &quot;'&quot; 
& &quot; WHERE BreederNo =&quot; & Val(Request.Form(&quot;txtBreederNo&quot;))
Tom
 
Do I have to declare the two variables txtPupsAvailable and txtBreederNo like this

var int_BreederNo = new Integer(Request.Form(&quot;txtBreederNo&quot;))
var str_PupsAvailable = new String(Request.Form(&quot;txtPupsAvailable&quot;))
 
Do I need to declare these 2 variables and do I need an if statement like

if (int_BreederNo!=&quot;undefined&quot; && str_PupsAvailable!=&quot;undefined&quot;)

in order to read in these 2 values from a form like this

</SCRIPT>
<meta name=&quot;Microsoft Theme&quot; content=&quot;indust 110, default&quot;>
</HEAD>
<BODY>
Please enter your Breeder Number and Update Information
<BR>
<FORM ACTION=&quot;Update.asp&quot; METHOD=POST NAME=form4 LANGUAGE=JavaScript
onsubmit=&quot;return form4_onsubmit()&quot;>

Breeder Number
<BR>
<INPUT TYPE=&quot;text&quot; NAME=txtBreederNo MAXLENGTH=50>
<BR>
Pups Available
<BR>
<INPUT TYPE=&quot;text&quot; NAME=txtPupsAvailable MAXLENGTH=3>
<BR>
<INPUT TYPE=&quot;submit&quot; VALUE=&quot;Send Details&quot; ID=submit4 NAME=submit4>
</FORM>

</BODY>
</HTML>

Could somebody help with this question?
 
It probably would be safer, if you assume the user will always enter values in both.
It appears you have onSubmit code already set up, so if you add the following to your form4_onsubmit function:
Code:
if (form4.txtBreederNo.Value.toString().length == 0){
   alert(&quot;You have forgotten to enter the breeder number.&quot;);
   form4.txtBreederNo.focus();
   return false;
}
if (form4.txtPupsAvailable.Value.toString().length == 0){
   alert(&quot;You have forgotten to enter the number of available pups.&quot;);
   form4.txtPupsAvailable.focus();
   return false;
}
Don't forget that the last line should be a return true in the event that it passed all conditions in the function.

If you do this client-side you shouldn't need to check again on the server side, but you could with
Code:
If Request.Form(&quot;txtPupsAvailable&quot;) <> &quot;&quot; AND Request.Form(&quot;txtBreederNo&quot;) <> &quot;&quot; Then
   'Do your database submit
Else
   'Redirect back to form
End If
Hope that was what you were looking for
-Tarwn ------------ My Little Dictionary ---------
Reverse Engineering - The expensive solution to not paying for proper documentation
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top