Forums

This topic is locked

How too..handcode an insert record and asp in acce

Posted 17 Jun 2003 18:21:49
1
has voted
17 Jun 2003 18:21:49 Richard Krawczak posted:
Hi there,

I’m trying to make an insert new record into my database with an asp file.
My flash insert-post movieclip post the variables and their values to the asp file.
But how to make an asp file that does the job is my problem.
All the nice features in dreamweaver, all make a lot of terrible code and then it is necessary to make a form in the file and to accept all kind of html which has to be deleted to keep a clean asp for my flash to work with. I tried, yes so I did but still my asp won’t work
My hand code books to help me, cover little about the inserting of a new record to the database. I just miss the right syntax

So if anyone has a hand-coded example of inserting a record into a database with variables coming from Flash, please place it on the board. I’m sure it will be enough to get me going again finding a right solution.
Why can’t asp be as simple as cfml where a simple <cfinsert would do the job in one line of code, I sometimes wonder.


Thanks for any contribution


JJF



Replies

Replied 18 Jun 2003 08:32:02
18 Jun 2003 08:32:02 Vince Baker replied:
THis is my template for inserts from asp. I dont use flash so cant help if there is any specical requirements there.... make sure you have an include to your connection file at the top of the page...


<%
sql ="INSERT INTO TABLE_NAME (Field_name, Field_name2) VALUES ('" & str & "','" & str & "')"
%>

<%
set InsertRecords = Server.CreateObject("ADODB.Command"
InsertRecords.ActiveConnection = MM_Paste_Conn_Here_STRING
InsertRecords.CommandText = sql
InsertRecords.CommandType = 1
InsertRecords.CommandTimeout = 0
InsertRecords.Prepared = true
InsertRecords.Execute()
%>

Regards
Vince

Visit my home: www.chez-vince.com

VBScript | ASP | HTML | SQL | Oracle | Hosting
Replied 18 Jun 2003 09:17:02
18 Jun 2003 09:17:02 Richard Krawczak replied:
Thanks Vince,

This is just what the doctor ordered.
Stil one question left.
The sql variable declaration in your code at the top makes a sort of concenated string of the values.
I see ' and I see " used
|My question: do numeric values and stringvalues and datevalues or for instance timevalues need the same " or ' surrounding them?
Or do nummeric values need another approach then stringvalues?

regards

JJF
Replied 18 Jun 2003 11:58:13
18 Jun 2003 11:58:13 Vince Baker replied:
The example doesnt show that very well....

Basically, the " is only there to allow string variables to be inserted. So if we had created 3 variables, 1 text, 1 date and 1 numeric you would have the following:

Dim strText, strDate, strNum

strText = "Some Text"
strDate = "04/01/03"
strNum = 45


sql ="INSERT INTO TABLE_NAME (TextFieldName, DateFieldName, NumericFieldName) VALUES ('" & strText & "','" & strDate & "," & strNum & ""

Text = Surrounded by ' ' single quotes
Dates = Surrounded by ' ' single quotes
Numeric = No quotes.

Hope that is a bit clearer.



Regards
Vince

Visit my home: www.chez-vince.com

VBScript | ASP | HTML | SQL | Oracle | Hosting
Replied 20 Jun 2003 14:58:30
20 Jun 2003 14:58:30 Richard Krawczak replied:
ohoh

Edited by - Jumping Jack Flash on 21 Jun 2003 18:35:53
Replied 20 Jun 2003 15:08:58
20 Jun 2003 15:08:58 Vince Baker replied:
The problem you are having is that the Update sql action is trying to put the no_updates as text rather than a dynamic value taken from your recordset.

I have amended your update code below. Should work but let me know if you have trouble as I cant test the syntax.


<%

set Command1 = Server.CreateObject("ADODB.Command"
Command1.ActiveConnection = MM_molk_conn_STRING
Command1.CommandText = "UPDATE posts SET no_replies= " & rs_count("no_replies" & " WHERE post_id= " & post_id
Command1.CommandType = 1
Command1.CommandTimeout = 0
Command1.Prepared = true
Command1.Execute()

%>



Regards
Vince

Visit my home: www.chez-vince.com

VBScript | ASP | HTML | SQL | Oracle | Hosting
Replied 20 Jun 2003 17:07:52
20 Jun 2003 17:07:52 Richard Krawczak replied:
Hi Vince

Have received your instructions and will work it out soon,
I let you know what the results are
And if you ever should need help with flash, you just call out my name
I'm deeply in your depth

JJF
www.molk.nl
Replied 21 Jun 2003 18:36:33
21 Jun 2003 18:36:33 Richard Krawczak replied:
Hi there Vince

I’ve amended my code like you suggested but it still doesn’t update. When using my flash front-end, it inserts a new record tot the reply table but don’t update the no_replies record in the posts table.
When exporting the insert_reply.asp file to the browser on my localhost, the insert_reply.asp gives an error telling me the syntax of the insert isn’t ok

I don't understand why? And when there is an error why does it still insert the new record? You should think the script would abort. The update to the posts table regarding no_replies don’t update. However there is no error message regarding to this update command? So realy I’m lost here.

My reply table consists of the columns:
reply_id autonumbering
post_id numeric
reply-name text
reply_title text
reply memo
reply_date date
reply_time time

I want to insert into this table using the post-id of the posts table which consists of the columns:
Post_id autonumbering
Author_name text
Author_title text
Post memo
Date_post date
Time_post time
No_replies numeric

The code of the insert_reply.asp:
--------------------------------------------

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/molk_conn.asp" -->
<%
Dim post_id,reply_title,reply_name,reply_email,reply

post_id=Request.Form("post_id"
reply_title=request.Form("reply_title"
reply_name=request.Form("reply_name"
reply_email=Request.Form("reply_email"
reply=Request.Form("reply"
%>
<%
sql ="INSERT INTO replies(post_id, reply_title, reply_name, reply_email, reply) VALUES("&post_id&",'" &reply_title& "','" & reply_name & "','" & reply_email & "','" & reply & "')"

set InsertRecords = Server.CreateObject("ADODB.Command"
InsertRecords.ActiveConnection = MM_molk_conn_STRING
InsertRecords.CommandText = sql
InsertRecords.CommandType = 1
InsertRecords.CommandTimeout = 0
InsertRecords.Prepared = true
InsertRecords.Execute()
%>
<%
Dim rs_count__MMColParam
rs_count__MMColParam = "1"
If (request.Form("post_id" <> "" Then
rs_count__MMColParam = request.Form("post_id"
End If
%>
<%
Dim rs_count
Dim rs_count_numRows

Set rs_count = Server.CreateObject("ADODB.Recordset"
rs_count.ActiveConnection = MM_molk_conn_STRING
rs_count.Source = "SELECT COUNT (reply_id) AS no_replies FROM replies WHERE post_id = " + Replace(rs_count__MMColParam, "'", "''" + ""
rs_count.CursorType = 0
rs_count.CursorLocation = 2
rs_count.LockType = 1
rs_count.Open()

rs_count_numRows = 0
%>

<%

set Command1 = Server.CreateObject("ADODB.Command"
Command1.ActiveConnection = MM_molk_conn_STRING
Command1.CommandText = "UPDATE posts SET no_replies ="&rs_count("no_replies"&" WHERE post_id= "&post_id
Commmand1.CommandType = 1
Command1.CommandTimeout = 0
Command1.Prepared = true
Command1.Execute()

%>
<%
rs_count.Close()
Set rs_count = Nothing
%>




Edited by - Jumping Jack Flash on 21 Jun 2003 18:37:37

Edited by - Jumping Jack Flash on 21 Jun 2003 18:45:35

Reply to this topic