We help IT Professionals succeed at work.

store data in SQL 7 table

sporfex
sporfex asked
on
Hi.

The code below doesn't work. What is wrong?

<%@ Language=VBScript %>
<%

'**************************
'* Connection starts here *
'**************************


set remoteconn=server.CreateObject("ADODB.connection")
remoteconn.Open "Provider=SQLOLEDB.1;Driver={SQL  Server};SERVER=madeleine;DATABASE=Intranet;UID=sa;PWD=;"



Datum = trim(Request.Form("MyTime"))  
Rubrik = trim(Request.Form("MyRubrik"))
Text = trim(Request.Form("MyText"))
Avdelning = trim(Request.Form("MyDepartment"))

remoteconn.execute "insert into Nyheter (Datum, Rubrik, Text, Avdelning) values ('" & MyTime & "','" & MyRubrik & "','" & MyText & "','" & MyDepartment & "')"

%>

No error messages.
Comment
Watch Question

Author

Commented:
I think it sends the date field 'Datum' as 1900-01-01 all the time and the other fields are empty.
So the connection shoul be okey? Something else with the code. Probably the date?

Datum is set to datetime on the SQL 7 server table.

?
BRONZE EXPERT

Commented:
do a response.write "insert into Nyheter (Datum, Rubrik, Text, Avdelning) values ('" & MyTime & "','"
& MyRubrik & "','" & MyText & "','" & MyDepartment & "')"

to see what the sql statment is being produced as, maybe a non null is null, for example are the names of the request(form_item) correct
BRONZE EXPERT

Commented:
if you want to enter a date into sql server use convert

i.e.

date_col = CONVERT(datetime,"&Request("date_item")&",103)

it must be formatted correctly, i.e. "09/09/2001"

Commented:
some things I noticed.
1. you need to handle single quotes in the data
2. You don't need "into"
3. Text might be a keyword, add []


Datum = replace(trim(Request.Form("MyTime")),"'","''")
Rubrik = replace(trim(Request.Form("MyRubrik")),"'","''")
Text = replace(trim(Request.Form("MyText")),"'","''")
Avdelning = replace(trim(Request.Form("MyDepartment")),"'","''")

remoteconn.execute "INSERT Nyheter (Datum, Rubrik, [Text], Avdelning) VALUES ('" & MyTime & "','"
& MyRubrik & "','" & MyText & "','" & MyDepartment & "')"

John

Commented:
and it looks like you are not putting the values gathered in four statements into the insert statement...

shouldn't this statement
remoteconn.execute "INSERT Nyheter (Datum, Rubrik, [Text], Avdelning) VALUES ('" & MyTime & "','"
& MyRubrik & "','" & MyText & "','" & MyDepartment & "')"

be changed to
remoteconn.execute "INSERT Nyheter (Datum, Rubrik, [Text], Avdelning) VALUES ('" & Datum & "','"
& Rubrik & "','" & Text & "','" & Avdelning & "')"

Author

Commented:
Response.write are

insert into Nyheter (Datum, Rubrik, Text, Avdelning) values ('','','','')

Notheing is posted...hmm

Author

Commented:
I noticed one thing myself. 'Text' isn't a good name for an object I guess?

Commented:
try my last post.  I think that you are using different variable names in your statement.  you set the value into Datum and then use MyTime in your insert statement.....

John

Commented:
did any of that info help you sporfex?

Author

Commented:
I'm home now but will try it first thing tomorrow.

Author

Commented:
John844 and others.
Have change the code to yours, still the same problem.

Response.write =

INSERT Nyheter (Datum, Rubrik, Information, Avdelning) VALUES ('','','','')

Author

Commented:
I have found the errors. Stupid errors.

Two of my text fields in the form was disabled.

How can I disable the fields and still send the data?
Commented:
in your form you just need to add a hidden field with your value in it.  

or if the text fields can be enabled and disabled through user interaction you need to use javascript to enable all form fields when the form is submitted.

John

Explore More ContentExplore courses, solutions, and other research materials related to this topic.