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

saving to access db 1

Status
Not open for further replies.

clientuser

Programmer
Apr 18, 2001
296
US
I have this page that I am trying to save data to an access db, but each time I click submit it just blinks for a sec like its doing something and then stops.. it also happens when I dont put anything in the fields and I have a script to check the fields, but even thats not working:

Code:
<% Response.Buffer = true %>
<!--#include file = "conn.asp"-->
<%
dim strdate 
strdate = now()
%>
<html>
<head>
<title>~~~~SA-Order entry~~~~</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
function check1(){
if (document.form1.fname.value =="" )
	{
		form1.fname.focus;
		error=1;
	}
else 
if (document.form1.lname.value=="")
	{
		form1.lname.focus;
		error=1;
	}
else 
if (document.form1.address.value=="")
	{
		form1.address.focus;
		error=1;
	}
else 
if (document.form1.city.value=="")
	{
		form1.city.focus;
		error=1;
	}
else 
if (document.form1.zip.value=="")
	{
		form1.zip.focus;
		error=1;
	}
else 
if (document.form1.status.value=="")
	{
		form1.status.focus;
		error=1;
	}
else
 { 
			form1.submit();
	}

}
</script>
</head>
<body bgcolor="#ffffff">
<form name="form1" method="post" action="addorder.asp" onSubmit="check1();">
  <table width="100%" border="0" cellspacing="5" cellpadding="5">
    <tr>
      <td bgcolor="#000000"><strong><font color="#FFFFFF">Enter in a new order:</font></strong></td>
    </tr>
  </table>
  <table width="40%" border="0" cellspacing="5" cellpadding="5">
    <tr>
      <td bgcolor="#666666"><table width="100%" border="0" cellpadding="5">
          <tr>
            <td bgcolor="#000000"><font color="#FFFFFF">Date order entered:</font>&nbsp&nbsp;<input name="dateentered" type="text" value="<%=strdate%>" id="dateentered" disabled="true"></td>
          </tr>
        </table>
        <table width="100%" border="0" cellpadding="5" cellspacing="0" bordercolor="#666666">
          <tr bgcolor="#CCCCCC"> 
            <td width="40%"><font color="#666666">Order number:</font></td>
            <td width="60%"><input name="ordnum" type="text" id="ordnum" size="20" maxlength="20"></td>
          </tr>
		  <tr bgcolor="#CCCCCC"> 
            <td width="40%"><font color="#666666">First Name:</font></td>
            <td width="60%"><input name="fname" type="text" id="fname" size="20" maxlength="20"></td>
          </tr>
          <tr bgcolor="#CCCCCC"> 
            <td><font color="#666666">Last Name:</font></td>
            <td><input name="lname" type="text" id="lname" size="20" maxlength="20"></td>
          </tr>
          <tr bgcolor="#CCCCCC"> 
            <td><font color="#666666">Address:</font></td>
            <td><input name="address" type="text" id="address" size="50" maxlength="50"></td>
          </tr>
          <tr bgcolor="#CCCCCC"> 
            <td><font color="#666666">City:</font></td>
            <td><input name="city" type="text" id="city" size="20" maxlength="20"></td>
          </tr>
          <tr bgcolor="#CCCCCC"> 
            <td><font color="#666666">State:</font></td>
            <td><input name="state" type="text" id="state" size="20" maxlength="20"></td>
          </tr>
		  <tr bgcolor="#CCCCCC"> 
            <td><font color="#666666">Zip:</font></td>
            <td><input name="zip" type="text" id="zip" size="20" maxlength="20"></td>
          </tr>
          <tr bgcolor="#CCCCCC"> 
            <td><font color="#666666">Status:</font></td>
            <td><input name="status" type="text" id="status" size="20" maxlength="20"></td>
          </tr>
		  
        </table>
        </table>
		
          <tr bgcolor="#CCCCCC"> 
            <td>&nbsp;</td>
            <td><input type="submit" name="Submit" value="Submit"></td>
          </tr>
        </table></td>
    </tr>
  </table>
<% 
dim strdateenter,strordnum,strfname,strlname,straddress,strcity,strstate,strzip,strstatus
strdateenter = Request.form("dateentered")
strordnum = Request.form("ordnum")
strfname = Request.form("fname")
strlname = Request.form("lname")
straddress = Request.form("address")
strcity = Request.form("city")
strstate = Request.form("state")
strzip = Request.form("zip")
strstatus = Request.form("status")

if  ( strdateenter <> "" and strordnum <> "" and strfname <> "" and strlname <> "" and  straddress <> "" and strcity <> "" and strstate <> "" and strzip <> "" and strstatus <> "") then
 		
		sql= "SELECT * FROM tblsa WHERE ordernum ='" & strordnum & "'"
		conn.ConnectionTimeout = 15
    		conn.CommandTimeout =  10
		conn.Mode = 3
		conn.Open
		rs.Open sql,conn,3,3
    
if rs.eof then
	rs.AddNew
	rs("DateEntered") = Request.form("dateentered")
	rs("ordernum") = Request.form("ordnum")
	rs("fname") = Request.form("fname")
	rs("lname") = Request.form("lname")
	rs("address") = Request.form("address")
	rs("city") = Request.form("city")
	rs("zip") = Request.form ("zip")
	rs("status") = Request.form ("status")
	rs.Update
	'Response.Redirect("default.asp")
	Response.write("Order Saved with no errors.")
else 
	Response.write("Order Already Exist")

end if
rs.close
set rs=nothing
conn.close
set conn=nothing
end if
%>
</form>
</html>
 
when you say it does nothing - what is being displayed on the screen - does the page reload at all?

you might want to add a debug ElseIf to this conditional statement...
Code:
if  ( strdateenter <> "" and strordnum <> "" and strfname <> "" and strlname <> "" and  straddress <> "" and strcity <> "" and strstate <> "" and strzip <> "" and strstatus <> "") then
...
elseif
  Response.Write "I havent written anything to the database"
end if

Tony
reddot.gif WIDTH=500 HEIGHT=2 VSPACE=3

 
the page seems to flicker like its going to save and then the fields that have data are cleared.

i also tried to run the page with no data so the javascript check would kick in, but it doesnt as well..

im fairly new to .asp so its driving me crazy
 
yes the page is addorder.asp i am trying to save the data to an access db.. isnt the tag:

<form name="form1" method="post" action="addorder.asp" onSubmit="check1();">

action="addorder.asp" being the page that its on now

onsubmit="check1();" letting the code run in the javascript to check for null fields?

am I totally off on this one???
 
try this for the javascript validation
Code:
<script language="JavaScript">
function check1(){
if (document.form1.fname.value =="" )
{
  form1.fname.focus;
  error=1;
  return false;
}
else if (document.form1.lname.value=="")
{
  form1.lname.focus;
  error=1;
  return false;
}
else if (document.form1.address.value=="")
{
  form1.address.focus;
  error=1;
  return false
}
else if (document.form1.city.value=="")
{
  form1.city.focus;
  error=1;
  return false;
}
else if (document.form1.zip.value=="")
{
  form1.zip.focus;
  error=1;
  return false;
}
else if (document.form1.status.value=="")
{
  form1.status.focus;
  error=1;
  return false;
}
else
  return true;

}
</script>
and change your <FORM> tag to this...
Code:
<form name="form1" method="post" action="addorder.asp" onSubmit="[b]return[/b] check1();">

Tony
reddot.gif WIDTH=500 HEIGHT=2 VSPACE=3

 
I updated the page but now when I click it with no data, it does nothing and when I try to save it flickers and clears the fields and doesnt save..

 
sorry - I didnt finish changing your function...
Code:
function check1(){
if (document.form1.fname.value =="" )
{
  alert("Please enter a first name");
  form1.fname.focus;
  error=1;
  return false;
}
else if (document.form1.lname.value=="")
{
  alert("Please enter a last name");
  form1.lname.focus;
  error=1;
  return false;
}
else if (document.form1.address.value=="")
{
  alert("Please enter an address");
  form1.address.focus;
  error=1;
  return false
}
else if (document.form1.city.value=="")
{
  alert("Please enter a city");
  form1.city.focus;
  error=1;
  return false;
}
else if (document.form1.zip.value=="")
{
  alert("Please enter a zip code");
  form1.zip.focus;
  error=1;
  return false;
}
else if (document.form1.status.value=="")
{
  alert("Please enter a status");
  form1.status.focus;
  error=1;
  return false;
}
else
  return true;

}

Your ASP code is currently making sure that the info is ONLY saved if there is infoamtion entered for EVERY field. Is this what you want?

Tony
reddot.gif WIDTH=500 HEIGHT=2 VSPACE=3

 
yes sir...

the javascript is working fine now, but saving is still not working... i do appreciate your help on this...
 
nope, i get none of the response.write messages.. it just flickers and the information thats there disappears

sorry to bother everyone, i hate asking for help....
 
not at all - thats why we come here.

try adding this and see if the message appears...
Code:
if  ( strdateenter <> "" and strordnum <> "" and strfname <> "" and strlname <> "" and  straddress <> "" and strcity <> "" and strstate <> "" and strzip <> "" and strstatus <> "") then
...
else
  Response.Write "I havent written anything to the database"
end if

Tony
reddot.gif WIDTH=500 HEIGHT=2 VSPACE=3

 
I tried:

Code:
if  ( strdateenter <> "" and strordnum <> "" and strfname <> "" and strlname <> "" and  straddress <> "" and strcity <> "" and strstate <> "" and strzip <> "" and strstatus <> "") then
 		
		sql= "SELECT * FROM tblsa WHERE ordernum ='" & strordnum & "'"
		conn.ConnectionTimeout = 15
    		conn.CommandTimeout =  10
		conn.Mode = 3
		conn.Open
		rs.Open sql,conn,3,3
else
response.write("I have not written anything to the database yet.")
End If

but im not sure thats what you wanted me to do?
 
nearly...
Code:
if  ( strdateenter <> "" and strordnum <> "" and strfname <> "" and strlname <> "" and  straddress <> "" and strcity <> "" and strstate <> "" and strzip <> "" and strstatus <> "") then
         
  sql= "SELECT * FROM tblsa WHERE ordernum ='" & strordnum & "'"
  conn.ConnectionTimeout = 15
  conn.CommandTimeout =  10
  conn.Mode = 3
  conn.Open
  rs.Open sql,conn,3,3
    
  if rs.eof then
    rs.AddNew
    rs("DateEntered") = Request.form("dateentered")
    rs("ordernum") = Request.form("ordnum")
    rs("fname") = Request.form("fname")
    rs("lname") = Request.form("lname")
    rs("address") = Request.form("address")
    rs("city") = Request.form("city")
    rs("zip") = Request.form ("zip")
    rs("status") = Request.form ("status")
    rs.Update
    'Response.Redirect("default.asp")
    Response.write("Order Saved with no errors.")
  else 
    Response.write("Order Already Exist")
  end if

  rs.close
  set rs=nothing
  conn.close
  set conn=nothing
else
  Response.Write "I have not written anything to the database"
end if

Tony
reddot.gif WIDTH=500 HEIGHT=2 VSPACE=3

 
hehe.. when I put that in, the page pulls up and the text in the response.write is right beside the submit button ..

 
ok, so that means that the following conditional is not being met
Code:
if  ( strdateenter <> "" and strordnum <> "" and strfname <> "" and strlname <> "" and  straddress <> "" and strcity <> "" and strstate <> "" and strzip <> "" and strstatus <> "") then
You are already doing this check before you submit the page (with the javascript) so you could remove it.

This would just leave...
Code:
<% 
sql= "SELECT * FROM tblsa WHERE ordernum ='" & strordnum & "'"
conn.ConnectionTimeout = 15
conn.CommandTimeout =  10
conn.Mode = 3
conn.Open
rs.Open sql,conn,3,3
    
if rs.eof then
  rs.AddNew
  rs("DateEntered") = Request.form("dateentered")
  rs("ordernum") = Request.form("ordnum")
  rs("fname") = Request.form("fname")
  rs("lname") = Request.form("lname")
  rs("address") = Request.form("address")
  rs("city") = Request.form("city")
  rs("zip") = Request.form("zip")
  rs("status") = Request.form("status")
  rs.Update
  'Response.Redirect("default.asp")
  Response.write("Order Saved with no errors.")
else 
  Response.write("Order Already Exists")
end if

rs.close
set rs=nothing
conn.close
set conn=nothing
%>

Tony
reddot.gif WIDTH=500 HEIGHT=2 VSPACE=3

 
I actually figured it out, however I am still going to give fester a star for all the help..

thanks again fester....!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top