|
|
|||||||||
|
|||||||||
|
|||||||||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Save your reputation with your customers. Learn how you can have embedding success with Advantage Database Server (ADS). |
|
#1
|
|||
|
|||
|
Syntax error when inserting a record
I am getting a syntax error although I don't think it's to do with my actual insert code. Error message and the line given has been highlighted:
Quote:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<head>
<title>Welcome to the Kennels Database System</title>
<link href="external.css" rel="stylesheet" type="text/css" />
</head>
<body>
<center>
<!-- MAIN TABLE -->
<table border=0 class="tableborder">
<tr>
<td colspan=2 class="bannerborder">
<% Response.Write FormatDateTime(Date, vbShortDate)
struser=session("user")
%>
<img src="images/logo.jpg" alt="banner" class="bannerimage">
</td>
</tr>
<tr>
<td valign="top" width=20% class="cellborder">
<p class="leftlinks">
<div id="curves">
<%
intlevel=session("level")
If intlevel=1 OR intlevel=2 then %>
Welcome, <%=struser%><br>
<% end if %>
<br>
<b class="top">
<b class="b1"></b>
<b class="b2"></b>
<b class="b3"></b>
<b class="b4"></b>
</b>
<dl id="links">
<dd>
<a href="start.asp">Main Page</a>
</dd>
<dd>
<a href="animals.asp">Animals</a>
</dd>
<dd>
<a href="customers.asp">Customers</a>
</dd>
<dd>
<a href="staff.asp">Staff</a>
</dd>
<dd>
<a href="vets.asp">Vets</a>
</dd>
<dd>
<a href="help.asp">Help</a>
</dd>
<dd>
<a href="default.asp">Logout</a>
</dd>
</dl>
<b class="bottom">
<b class="b4"></b>
<b class="b3"></b>
<b class="b2"></b>
<b class="b1"></b>
</b>
</div>
</p>
</td>
</p>
</td>
<td valign="top" class="padded-table">
<div class="content">
<!-- 84 LOGIN CHECK -->
<%
intlevel=Session("level")
If intlevel=1 OR intlevel=2 then
Response.CacheControl = "no-cache"
Response.AddHeader "Pragma", "no-cache"
Response.Expires = -1 %>
<!-- 95 CONTENT OF TABLE-START -->
<s2>Add an animal</s2><br>
<br><br>
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("kennels.mdb"))
' Receiving values from Form
AnimalTypeID = Request.Form("AnimalTypeID")
CustomerID = Request.Form("CustomerID")
VetID = Request.Form("VetID")
AnimalName = Request.Form("AnimalName")
Breed = Request.Form("Breed")
AnimalDescription = Request.Form("AnimalDescription")
Colour = Request.Form("Colour")
gender = Request.Form("gender")
neutered = Request.Form("neutered")
DateOfBirth = Request.Form("DateOfBirth")
LastVaccinationDate = Request.Form("LastVaccinationDate")
FeedingBrand = Request.Form("FeedingBrand")
FeedingRequirements = Request.Form("FeedingRequirements")
DateIn = Request.Form("DateIn")
DateOut = Request.Form("DateOut")
Misc = Request.Form("Misc")
'sql1 adds values in if the date in/out fields have not been completed (they are not compulsory), sql2 adds in the date in/out fields
sql1 = "insert into tblanimals (AnimalTypeID, CustomerID, VetID, AnimalName, Breed, AnimalDescription, Colour, gender, neutered, DateOfBirth, LastVaccinationDate, FeedingBrand, FeedingRequirements, Misc)
values ("&AnimalTypeID&","&CustomerID&","&VetID&", '" & AnimalName & "', '" & Breed & "', '" & AnimalDescription & "', '" & Colour & "', _'" & gender & "', '" & neutered & "', #" & DateOfBirth & "#, #" &
LastVaccinationDate & "#, '" & FeedingBrand & "', '" & FeedingRequirements & "', '" & Misc & "')"
sql2 = "insert into tblanimals (AnimalTypeID, CustomerID, VetID, AnimalName, Breed, AnimalDescription, Colour, gender, neutered, DateOfBirth, LastVaccinationDate, FeedingBrand, FeedingRequirements, DateIn,
DateOut, Misc) values ("&AnimalTypeID&","&CustomerID&","&VetID&", '" & AnimalName & "', '" & Breed & "', '" & AnimalDescription & "', '" & Colour & "', _'" & gender & "', '" & neutered & "', #" & DateOfBirth
& "#, #" & LastVaccinationDate & "#, '" & FeedingBrand & "', '" & FeedingRequirements & "', #" & DateIn & "#, #" & DateOut & "#, '" & Misc & "')"
'Checks for blank values
If AnimalTypeID="" OR CustomerID="" OR VetID="" OR AnimalName="" OR Breed="" OR AnimalDescription="" OR Colour="" OR gender="" OR neutered="" OR DateOfBirth="" OR LastVaccinationDate="" OR FeedingBrand="" OR
FeedingRequirements="" OR Misc="" THEN
%> You did not fill in all the fields.<a href="addnewanimal.asp">Click here to go back.</a>
elseif DateIn="" OR dateout="" THEN
conn.execute sql1
%>
Customer added!<br>
<br>
<a href="animals.asp">Back to Animal Section</a>
<%
else
conn.execute sql2
%>
Customer added!<br>
<br>
<a href="animals.asp">Back to Animal Section</a>
<%
end if
end if
conn.Close
Set conn = Nothing
%>
<!-- CONTENT OF TABLE-END -->
<% else %>
You are not logged in. Click <a href="default.asp">here</a> to return to the login page.
<% end if %>
</div>
</td>
</tr>
</table>
</body>
</html>
|
|
#2
|
|||
|
|||
|
I don't really understand why you have a "_" before your gender field. Try this.
Code:
sql1 = "insert into tblanimals (AnimalTypeID, CustomerID, VetID, AnimalName, Breed, AnimalDescription, Colour, gender, neutered, DateOfBirth, LastVaccinationDate, FeedingBrand, FeedingRequirements, Misc)
values ("&AnimalTypeID&","&CustomerID&","&VetID&", '" & AnimalName & "', '" & Breed & "', '" & AnimalDescription & "', '" & Colour & "', '" & gender & "', '" & neutered & "', #" & DateOfBirth & "#, #" &
LastVaccinationDate & "#, '" & FeedingBrand & "', '" & FeedingRequirements & "', '" & Misc & "')"
sql2 = "insert into tblanimals (AnimalTypeID, CustomerID, VetID, AnimalName, Breed, AnimalDescription, Colour, gender, neutered, DateOfBirth, LastVaccinationDate, FeedingBrand, FeedingRequirements, DateIn,
DateOut, Misc) values ("&AnimalTypeID&","&CustomerID&","&VetID&", '" & AnimalName & "', '" & Breed & "', '" & AnimalDescription & "', '" & Colour & "', '" & gender & "', '" & neutered & "', #" & DateOfBirth
& "#, #" & LastVaccinationDate & "#, '" & FeedingBrand & "', '" & FeedingRequirements & "', #" & DateIn & "#, #" & DateOut & "#, '" & Misc & "')"
__________________
[Video] 7 Devastating Effects of Oil Depletion Why Beautiful Young Women Can't Marry Rich and Powerful Men Your Birthday Cake Sucks! For more interesting reads, visit IcyBlog. |
|
#3
|
||||
|
||||
|
Hi,
May not solve your problem but missing "<%" Code:
If AnimalTypeID="" OR CustomerID="" OR VetID="" OR AnimalName="" OR Breed="" OR AnimalDescription="" OR Colour="" OR gender="" OR neutered="" OR DateOfBirth="" OR LastVaccinationDate="" OR FeedingBrand="" OR FeedingRequirements="" OR Misc="" THEN %> You did not fill in all the fields.<a href="addnewanimal.asp">Click here to go back.</a> <% elseif DateIn="" OR dateout="" THEN |
|
#4
|
|||
|
|||
|
I have removed the underscore and added the <% in, but same error.
|
|
#5
|
|||
|
|||
|
Try replacing the "#"s with " ' "s. It might be a varchar field.
|
|
#6
|
|||
|
|||
|
Well it's a date/time field and works okay using the "#"'s when updating the records, just can't seem to add new ones for some reason
![]() |
|
#7
|
||||
|
||||
|
which is line 161??
use response.write and post the output of ur query here. |
|
#8
|
|||
|
|||
|
I highlighted the line in bold in my original post.
Response.write of both queries: Code:
insert into tblanimals (AnimalTypeID, CustomerID, VetID, AnimalName, Breed, AnimalDescription, Colour, gender, neutered, DateOfBirth, LastVaccinationDate, FeedingBrand, FeedingRequirements, Misc) values (2,3,1, 'Lassiette', 'Moggy', 'Fiesty Feline', 'Brown', '', '', #15/02/2002#, #30/02/2006#, 'Pedigree Chummy', 'Twice a day', '') insert into tblanimals (AnimalTypeID, CustomerID, VetID, AnimalName, Breed, AnimalDescription, Colour, gender, neutered, DateOfBirth, LastVaccinationDate, FeedingBrand, FeedingRequirements, DateIn, DateOut, Misc) values (2,3,1, 'Lassiette', 'Moggy', 'Fiesty Feline', 'Brown', '', '', #15/02/2002#, #30/02/2006#, 'Pedigree Chummy', 'Twice a day', ##, ##, '') |
|
#9
|
||||
|
||||
|
Quote:
I couldn't see any lines highlighted in your original post, which line is 161? I dont think the problem is caused by your sql statement, it appears to be a syntax error, post your code again with the error highlighted. |
|
#10
|
|||
|
|||
|
It's kind of hard to highlight, it's literally a line with just the word else on. But code again as requested
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<head>
<title>Welcome to the Kennels Database System</title>
<link href="external.css" rel="stylesheet" type="text/css" />
</head>
<body>
<center>
<!-- MAIN TABLE -->
<table border=0 class="tableborder">
<tr>
<td colspan=2 class="bannerborder">
<% Response.Write FormatDateTime(Date, vbShortDate)
struser=session("user")
%>
<img src="images/logo.jpg" alt="banner" class="bannerimage">
</td>
</tr>
<tr>
<td valign="top" width=20% class="cellborder">
<p class="leftlinks">
<div id="curves">
<%
intlevel=session("level")
If intlevel=1 OR intlevel=2 then %>
Welcome, <%=struser%><br>
<% end if %>
<br>
<b class="top">
<b class="b1"></b>
<b class="b2"></b>
<b class="b3"></b>
<b class="b4"></b>
</b>
<dl id="links">
<dd>
<a href="start.asp">Main Page</a>
</dd>
<dd>
<a href="animals.asp">Animals</a>
</dd>
<dd>
<a href="customers.asp">Customers</a>
</dd>
<dd>
<a href="staff.asp">Staff</a>
</dd>
<dd>
<a href="vets.asp">Vets</a>
</dd>
<dd>
<a href="help.asp">Help</a>
</dd>
<dd>
<a href="default.asp">Logout</a>
</dd>
</dl>
<b class="bottom">
<b class="b4"></b>
<b class="b3"></b>
<b class="b2"></b>
<b class="b1"></b>
</b>
</div>
</p>
</td>
</p>
</td>
<td valign="top" class="padded-table">
<div class="content">
<!-- 84 LOGIN CHECK -->
<%
intlevel=Session("level")
If intlevel=1 OR intlevel=2 then
Response.CacheControl = "no-cache"
Response.AddHeader "Pragma", "no-cache"
Response.Expires = -1 %>
<!-- 95 CONTENT OF TABLE-START -->
<s2>Add an animal</s2><br>
<br><br>
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("kennels.mdb"))
' Receiving values from Form
AnimalTypeID = Request.Form("AnimalTypeID")
CustomerID = Request.Form("CustomerID")
VetID = Request.Form("VetID")
AnimalName = Request.Form("AnimalName")
Breed = Request.Form("Breed")
AnimalDescription = Request.Form("AnimalDescription")
Colour = Request.Form("Colour")
gender = Request.Form("gender")
neutered = Request.Form("neutered")
DateOfBirth = Request.Form("DateOfBirth")
LastVaccinationDate = Request.Form("LastVaccinationDate")
FeedingBrand = Request.Form("FeedingBrand")
FeedingRequirements = Request.Form("FeedingRequirements")
DateIn = Request.Form("DateIn")
DateOut = Request.Form("DateOut")
Misc = Request.Form("Misc")
'sql1 adds values in if the date in/out fields have not been completed (they are not compulsory), sql2 adds in the date in/out fields
sql11 = "insert into tblanimals (AnimalTypeID, CustomerID, VetID, AnimalName, Breed, AnimalDescription, Colour, gender, neutered, DateOfBirth, LastVaccinationDate, FeedingBrand, FeedingRequirements, Misc) values ("&AnimalTypeID&","&CustomerID&","&VetID&", '" & AnimalName & "', '" & Breed & "', '" & AnimalDescription & "', '" & Colour & "', '" & gender & "', '" & neutered & "', #" & DateOfBirth & "#, #" & LastVaccinationDate & "#, '" & FeedingBrand & "', '" & FeedingRequirements & "', '" & Misc & "')"
sql12 = "insert into tblanimals (AnimalTypeID, CustomerID, VetID, AnimalName, Breed, AnimalDescription, Colour, gender, neutered, DateOfBirth, LastVaccinationDate, FeedingBrand, FeedingRequirements, DateIn, DateOut, Misc) values ("&AnimalTypeID&","&CustomerID&","&VetID&", '" & AnimalName & "', '" & Breed & "', '" & AnimalDescription & "', '" & Colour & "', '" & gender & "', '" & neutered & "', #" & DateOfBirth & "#, #" & LastVaccinationDate & "#, '" & FeedingBrand & "', '" & FeedingRequirements & "', #" & DateIn & "#, #" & DateOut & "#, '" & Misc & "')"
sql1 = "insert into tblanimals (AnimalTypeID, CustomerID, VetID, AnimalName, Breed, AnimalDescription, Colour, gender, neutered, DateOfBirth, LastVaccinationDate, FeedingBrand, FeedingRequirements, Misc) values ("&AnimalTypeID&","&CustomerID&","&VetID&", '" & AnimalName & "', '" & Breed & "', '" & AnimalDescription & "', '" & Colour & "', '" & gender & "', '" & neutered & "', #" & DateOfBirth & "#, #" & LastVaccinationDate & "#, '" & FeedingBrand & "', '" & FeedingRequirements & "', '" & Misc & "')"
sql2 = "insert into tblanimals (AnimalTypeID, CustomerID, VetID, AnimalName, Breed, AnimalDescription, Colour, gender, neutered, DateOfBirth, LastVaccinationDate, FeedingBrand, FeedingRequirements, DateIn, DateOut, Misc) values ("&AnimalTypeID&","&CustomerID&","&VetID&", '" & AnimalName & "', '" & Breed & "', '" & AnimalDescription & "', '" & Colour & "', '" & gender & "', '" & neutered & "', #" & DateOfBirth & "#, #" & LastVaccinationDate & "#, '" & FeedingBrand & "', '" & FeedingRequirements & "', #" & DateIn & "#, #" & DateOut & "#, '" & Misc & "')"
'Checks for blank values
If AnimalTypeID="" OR CustomerID="" OR VetID="" OR AnimalName="" OR Breed="" OR AnimalDescription="" OR Colour="" OR gender="" OR neutered="" OR DateOfBirth="" OR LastVaccinationDate="" OR FeedingBrand="" OR FeedingRequirements="" OR Misc="" THEN
%> You did not fill in all the fields.<a href="addnewanimal.asp">Click here to go back.</a>
<% elseif DateIn="" OR dateout="" THEN
conn.execute sql1
%>
Customer added!<br>
<br>
<a href="animals.asp">Back to Animal Section</a>
<%
else
conn.execute sql2
%>
Customer added!<br>
<br>
<a href="animals.asp">Back to Animal Section</a>
<%
end if
end if
conn.Close
Set conn = Nothing
%>
<!-- CONTENT OF TABLE-END -->
<% else %>
You are not logged in. Click <a href="default.asp">here</a> to return to the login page.
<% end if %>
</div>
</td>
</tr>
</table>
</body>
</html>
|
|
#11
|
||||
|
||||
|
ok u did highlight else in first post.
in sql2, u have no date for DateIn and DateOut, may be thats throwing the error as database might not accept null datetime. |
|
#12
|
|
|