| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
adding item to database
i was just wondering if someone could help me out and see whats wrong with this
code because i tryed to run it and it was giving me an error on the mySQL line here is the code <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Untitled Document</title> </head> <% myDSN = "DBQ=" & server.MapPath("OnlineDatabase.mdb")& ";Driver={Microsoft Access Driver (*.mdb)};" set Conn = server.CreateObject("ADODB.Connection") mySQL = "Insert Into [ProductTable] ([Product ID],[Product Name],[Product Description],[Product Price],[Product Quantity],[Category ID],[Product Image],[Size]) VALUES('"& Request.Form("Product Name") &"; Request.Form("Product Description") &"; Request.Form("Product Price") &"; Request.Form("Product Quantity") &"; Request.Form("Categoy ID") &"; Request.Form("Product Image") &"; Request.Form("Size");" Conn.Open myDSN Conn.Update mySQL Conn.Close Set conn = Nothing %> <body> <p>Congratulations you have</p> <p>successfuly added a new product</P> </body> </html> if someone could get back to me with whats wrong with it. this is the error message im getting when i try and run it Microsoft VBScript compilation error '800a0409' Unterminated string constant /submitadd.asp, line 11 mySQL = "Insert Into [ProductTable] ([Product ID],[Product Name],[Product Description],[Product Price],[Product Quantity],[Category ID],[Product Image],[Size]) |
|
#2
|
||||
|
||||
|
If the data types are text (string), then surround the variables with single quotes ('). If their numbers don't surround them with single quotes.
Code:
VALUES('" & Request.Form("ProductName") & "', '" & Request.Form("ProductDescription") & "', '" & Request.Form("ProductPrice") & "', '" & Request.Form("ProductQuantity") & "', '" & Request.Form("CategoryID") & "', '" & Request.Form("ProductImage") & "', '" & Request.Form("Size") & "'"
|
|
#3
|
|||
|
|||
|
error on mySQL line
mySQL = "Insert Into [ProductTable] ([Product ID],[Product Name],[Product Description],[Product Price],[Product Quantity],[Category ID],[Product Image],[Size])
Microsoft VBScript compilation error '800a0409' Unterminated string constant /submitadd.asp, line 11 mySQL = "Insert Into [ProductTable] ([Product ID],[Product Name],[Product Description],[Product Price],[Product Quantity],[Category ID],[Product Image],[Size])that is the line and and error on that line and im not sure what is wrong with it |
|
#4
|
||||
|
||||
|
Try my suggestion.
|
|
#5
|
|||
|
|||
|
Quote:
i did the suggestion you told me about and im still getting that same error |
|
#6
|
|||
|
|||
|
Try as coded below, don't use single quotes.
line 11 is not terminated, put a double quote at the end ... ,[Size])" line 12 - remove the single quote ' at character 9 see below: Code:
VALUES("& Request.Form("Product Name") &";
not
VALUES('"& Request.Form("Product Name") &";
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<%
myDSN = "DBQ=" & server.MapPath("OnlineDatabase.mdb")& ";Driver={Microsoft Access Driver (*.mdb)};"
set Conn = server.CreateObject("ADODB.Connection")
mySQL = "Insert Into [ProductTable]" "([Product ID],[Product Name],[Product Description],[Product Price],[Product Quantity],[Category ID],[Product Image],[Size])"
VALUES("& Request.Form("Product Name") &"; Request.Form("Product Description") &"; Request.Form("Product Price") &"; Request.Form("Product Quantity") &"; Request.Form("Categoy ID") &"; Request.Form("Product Image") &"; Request.Form("Size");"
Conn.Open myDSN
Conn.Update mySQL
Conn.Close
Set conn = Nothing
%>
<body>
<p>Congratulations you have</p>
<p>successfuly added a new product</P>
</body>
</html>
|
|
#7
|
|||
|
|||
|
Quote:
i did that change and i got this error now Microsoft VBScript compilation error '800a03ee' Expected ')' /submitadd.asp, line 12 VALUES("& Request.Form("Product Name") &"; Request.Form("Product Description") &"; Request.Form("Product Price") &"; Request.Form("Product Quantity") &"; Request.Form("Categoy ID") &"; Request.Form("Product Image") &"; Request.Form("Size");" |
|
#8
|
|||
|
|||
|
yes, there is much more going on with your code than i picked up on at first glance. try this below: using the codepage and vbscript header, save your page as an ASP file
If that doesn't work try a whole different approach as in option 2, making sure to rename your fields in the ASP file and in the access datbase "WITHOUT" the spaces. Code:
<%@ LANGUAGE="VBScript" codepage="1252" %>
<%
myDSN = "DBQ=" & server.MapPath("OnlineDatabase.mdb")& ";Driver={Microsoft Access Driver (*.mdb)};"
set Conn = server.CreateObject("ADODB.Connection")
mySQL = "Insert Into [ProductTable]" & "([Product ID],[Product Name],[Product Description],[Product Price],[Product Quantity],[Category ID],[Product Image],[Size])"
& "VALUES (" & Request.Form("Product Name")" & "Request.Form("Product Description")" & "Request.Form("Product Price")");"
Conn.Open myDSN
Conn.Update mySQL
Conn.Close
Set conn = Nothing
%>
<html>
<head>
<title>Untitled Document</title>
</head>
<body>
<p>Congratulations you have</p>
<p>successfuly added a new product</P>
</body>
</html>
OPTION 2
Dim str ProductName
Dim str ProductDescription
.....ETC.
Function CheckStr(str)
checkit = Replace(str,"'","''")
End Function
strProductName = Request.Form("ProductName")
strProductDescription = Request.Form("ProductDescription")
.....ETC.
ProductName = CheckStr(ProductName)
ProductDescription = CheckStr(ProductDescription)
.....ETC.
strSQL = "INSERT INTO ProductTable " _
& "(ProductName, ProductDescription, ) " _
& "VALUES (" & ProductName & ", '" _
& ProductDescription & "', '" _
.....ETC.
& ProductPrice & "');" 'NOTE CLOSING HERE, FOR LAST FIELD
|
![]() |
| Viewing: ASP Free Forums > Programming > Code Bank > adding item to database |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|