|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now! |
|
#1
|
|||
|
|||
|
Asp page error
I have been getting this error page
Error Type: Microsoft JET Database Engine (0x80004005) Field 'Company.Name' cannot be a zero-length string. /test2/test2.asp, line 158 I know that the reason is because on the textfield on the form is empty. I am trying to find how to fix it by adding an if statement that will cause it to warn browsers to correct the information before submitting. I don't know where to put the if statement. The full scripts looks like: <%@LANGUAGE="VBSCRIPT"%> <% ' *** Logout the current user. MM_Logout = CStr(Request.ServerVariables("URL")) & "?MM_Logoutnow=1" If (CStr(Request("MM_Logoutnow")) = "1") Then Session.Contents.Remove("MM_Username") Session.Contents.Remove("MM_UserAuthorization") MM_logoutRedirectPage = "Login.asp" ' redirect with URL parameters (remove the "MM_Logoutnow" query param). if (MM_logoutRedirectPage = "") Then MM_logoutRedirectPage = CStr(Request.ServerVariables("URL")) If (InStr(1, UC_redirectPage, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then MM_newQS = "?" For Each Item In Request.QueryString If (Item <> "MM_Logoutnow") Then If (Len(MM_newQS) > 1) Then MM_newQS = MM_newQS & "&" MM_newQS = MM_newQS & Item & "=" & Server.URLencode(Request.QueryString(Item)) End If Next if (Len(MM_newQS) > 1) Then MM_logoutRedirectPage = MM_logoutRedirectPage & MM_newQS End If Response.Redirect(MM_logoutRedirectPage) End If %> <!--#include file="Connections/Test2.asp" --> <% ' *** Restrict Access To Page: Grant or deny access to this page MM_authorizedUsers="one" MM_authFailedURL="fail.htm" MM_grantAccess=false If Session("MM_Username") <> "" Then If (false Or CStr(Session("MM_UserAuthorization"))="") Or _ (InStr(1,MM_authorizedUsers,Session("MM_UserAuthorization"))>=1) Then MM_grantAccess = true End If End If If Not MM_grantAccess Then MM_qsChar = "?" If (InStr(1,MM_authFailedURL,"?") >= 1) Then MM_qsChar = "&" MM_referrer = Request.ServerVariables("URL") if (Len(Request.QueryString()) > 0) Then MM_referrer = MM_referrer & "?" & Request.QueryString() MM_authFailedURL = MM_authFailedURL & MM_qsChar & "accessdenied=" & Server.URLEncode(MM_referrer) Response.Redirect(MM_authFailedURL) End If %> <% ' *** Edit Operations: declare variables Dim MM_editAction Dim MM_abortEdit Dim MM_editQuery Dim MM_editCmd Dim MM_editConnection Dim MM_editTable Dim MM_editRedirectUrl Dim MM_editColumn Dim MM_recordId Dim MM_fieldsStr Dim MM_columnsStr Dim MM_fields Dim MM_columns Dim MM_typeArray Dim MM_formVal Dim MM_delim Dim MM_altVal Dim MM_emptyVal Dim MM_i MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME")) If (Request.QueryString <> "") Then MM_editAction = MM_editAction & "?" & Request.QueryString End If ' boolean to abort record edit MM_abortEdit = false ' query string to execute MM_editQuery = "" %> <% ' *** Insert Record: set variables If (CStr(Request("MM_insert")) = "form4") Then MM_editConnection = MM_Test2_STRING MM_editTable = "Company" MM_editRedirectUrl = "test2-1.asp" MM_fieldsStr = "Name|value|Address|value|CEO|value" MM_columnsStr = "Name|',none,''|Address|',none,''|CEO|',none,''" ' create the MM_fields and MM_columns arrays MM_fields = Split(MM_fieldsStr, "|") MM_columns = Split(MM_columnsStr, "|") ' set the form values For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2 MM_fields(MM_i+1) = CStr(Request.Form(MM_fields(MM_i))) Next ' append the query string to the redirect URL If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString Else MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString End If End If End If %> <% ' *** Insert Record: construct a sql insert statement and execute it Dim MM_tableValues Dim MM_dbValues If (CStr(Request("MM_insert")) <> "") Then ' create the sql insert statement MM_tableValues = "" MM_dbValues = "" For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2 MM_formVal = MM_fields(MM_i+1) MM_typeArray = Split(MM_columns(MM_i+1),",") MM_delim = MM_typeArray(0) If (MM_delim = "none") Then MM_delim = "" MM_altVal = MM_typeArray(1) If (MM_altVal = "none") Then MM_altVal = "" MM_emptyVal = MM_typeArray(2) If (MM_emptyVal = "none") Then MM_emptyVal = "" If (MM_formVal = "") Then MM_formVal = MM_emptyVal Else If (MM_altVal <> "") Then MM_formVal = MM_altVal ElseIf (MM_delim = "'") Then ' escape quotes MM_formVal = "'" & Replace(MM_formVal,"'","''") & "'" Else MM_formVal = MM_delim + MM_formVal + MM_delim End If End If If (MM_i <> LBound(MM_fields)) Then MM_tableValues = MM_tableValues & "," MM_dbValues = MM_dbValues & "," End If MM_tableValues = MM_tableValues & MM_columns(MM_i) MM_dbValues = MM_dbValues & MM_formVal Next MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")" If (Not MM_abortEdit) Then ' execute the insert Set MM_editCmd = Server.CreateObject("ADODB.Command") MM_editCmd.ActiveConnection = MM_editConnection MM_editCmd.CommandText = MM_editQuery MM_editCmd.Execute MM_editCmd.ActiveConnection.Close If (MM_editRedirectUrl <> "") Then Response.Redirect(MM_editRedirectUrl) End If End If End If %> <% Dim rsinfo Dim rsinfo_numRows Set rsinfo = Server.CreateObject("ADODB.Recordset") rsinfo.ActiveConnection = MM_Test2_STRING rsinfo.Source = "SELECT * FROM Company ORDER BY Name ASC" rsinfo.CursorType = 0 rsinfo.CursorLocation = 2 rsinfo.LockType = 1 rsinfo.Open() rsinfo_numRows = 0 %> <% Dim Repeat1__numRows Dim Repeat1__index Repeat1__numRows = 10 Repeat1__index = 0 rsinfo_numRows = rsinfo_numRows + Repeat1__numRows %> <html> <head> <title>BetaTesting Page</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <div align="center"> <h1>Test2</h1> <table width="60%" border="1" align="center" cellpadding="2" cellspacing="2"> <tr> <td width="33%"><font size="4"><strong>Name</strong></font></td> <td width="33%"><font size="4"><strong>Address</strong></font></td> <td width="33%"><font size="4"><strong>CEO</strong></font></td> </tr> <% While ((Repeat1__numRows <> 0) AND (NOT rsinfo.EOF)) %> <tr> <td width="33%"><%=(rsinfo.Fields.Item("Name").Value)%></td> <td width="33%"><%=(rsinfo.Fields.Item("Address").Value)%></td> <td width="33%"><%=(rsinfo.Fields.Item("CEO").Value)%></td> </tr> <% Repeat1__index=Repeat1__index+1 Repeat1__numRows=Repeat1__numRows-1 rsinfo.MoveNext() Wend %> </table> <p>Or ADD Records</p> <table width="60%" border="1" cellspacing="5" cellpadding="5"> <tr> <td width="33%" height="31"><strong><font size="4">Name</font></strong></td> <td width="33%"><strong><font size="4">Address</font></strong></td> <td width="33%"><strong><font size="4">CEO</font></strong></td> </tr> </table> <form name="form4" method="POST" action="<%=MM_editAction%>"> <input name="Name" type="text" id="Name" size="25%"> <input name="Address" type="text" id="Address" size="25%"> <input name="CEO" type="text" id="CEO" size="25%"> <input type="hidden" name="MM_insert" value="form4"> <input type="submit" name="Submit" value="Add Record"> </form> <p><a href="<%= MM_Logout %>"><br> <br> Log Out</a> <br> </p> </div> </body> </html> <% rsinfo.Close() Set rsinfo = Nothing %> any help appreciated and any ideas beside adding "IF" statement to fix this problem are welcome. Thanks in Advance. obi |
|
#2
|
|||
|
|||
|
What do you mean you don't know where or what to do?
Aren't you the one who wrote that script? Don't worry, I'm far from behing some sort of "code police/forum police" I have better things to do...but I look at your code and you've got plenty of IF's statements so at some point you should've known why you've put them there no ??? Maybe you're not the one that created this and your stuck to fix it right ? Ya...I know that feeling... The idea is to VALIDATE **SERVER SIDE** the data *BEFORE* you actually INSERT it(of whatever) into your database. So assuming I have a <form>...</form> with some <textfield> doesn't matter how many its simply an example... Now when my <form>...</form> is submitted, I retrieve the value from my <form>...</form> into variables. I then VALIDATE these variables if I want/need to. So in your case, find out what/where it is retrieving the data and simply do something like: <% Dim MyVariable MyVariable = Trim(Request.Form("txtTextbox1")) 'NOTE: I've assumed that your <form>...</form> was submitted using the POST method. I've also assumed that you had a <textbox> named *txtTextbox1*. Again, this is only an example. 'Now, you must validate(if needed) the variable MyVariable If MyVariable = "" Then ...Ah ha!!! the user didn't enter data into my txtTextbox1 field... ...so I can print an error message OR redirect him so that he must fill in the field... End If ...Continue code to make the INSERT(or whatever) inside your database... %> Hope this helps! Sincerely Vlince |
|
#3
|
||||
|
||||
|
Vlince is right, and his way will work for everything.
However, if this page is for a company intranet or other site where you know users will have javascript enabled, you can save time for the users and reduce the load on the server by using some client-side validation with javascript. There are lots of scripts available for checking things like empty fields or incorrectly formatted entries. Google for "javascript form field validation". If this is for a general internet site though, you probably want to rely on server side validation. As a suggestion, be sure to put some mark, like '*' to denote required fields, so the user knows what they need to fill in. Just my .02
__________________
--Dave-- U2kgSG9jIExlZ2VyZSBTY2lzLCBOaW1pdW0gRXJ1ZGl0aW9uaXMgSGFiZXM= |
|
#4
|
|||
|
|||
|
Thank you Vlince and Karsh44,
I didn't write these codes, Dreamweaver MX did it for me. I am pretty new to codes. |
|
#5
|
|||
|
|||
|
Hei after playing with the codes for a while I figured how to make it works.
Thanks again for both of you. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > Asp page error |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|