www.webdeveloper.com
Results 1 to 2 of 2

Thread: Would this insert into multiple tables work

  1. #1
    Join Date
    Jan 2006
    Posts
    3

    Would this insert into multiple tables work

    Hi

    a friend of mine asked me to help him out with his school asignment. Now he heard I did some stuff with php and knows amongst other things I have insert into multiple tables all sorted out within pages that I did. He asked me to help him out with Dreamweaver MX 2004 and asp to do the same thing. Now I am not familiar with it that much so I asked another friend to help us. He did send me an example, and I sort of recode it and came up with this code. I wonder if it would work. If someone would just go through it in keep me in the right direction I would really appreciate it. Thanks.

    Here is the code. There is a table info, that holds general information about and insert. There are also three other tables that store texts, fhotos and sounds. They are all related to info table by ID. Now my logic was. First store photo data into photo table, get max ID and put it into inf table. Now in php I would just define MAX ID aa variable and put that variable into INSERT query, but in asp I am not sure if I got it right.

    <%
    If Request("ins") <> "" Then

    if(Request("Text00") <> "") then INS__P1 = Request("Text00")
    if(Request("Text01") <> "") then INS__P2 = Request("Text01")
    if(Request("Text02") <> "") then INS__P3 = Request("Text02")
    if(Request("Text03") <> "") then INS__P4 = Request("Text03")
    if(Request("Text04") <> "") then INS__P5 = Request("Text04")
    if(Request("Text05") <> "") then INS__P6 = Request("Text05")
    %>
    <%
    set INS = Server.CreateObject("ADODB.Command")
    INS.ActiveConnection = MM_FaksDipl_STRING
    INS.CommandText = "INSERT INTO texti (Text00, Text01, Text02, Text03, Text04, Text05) VALUES ('" + Replace(INS__P1, "'", "''") + "', '" + Replace(INS__P2, "'", "''") + "', '" + Replace(INS__P3, "'", "''") + "','" + Replace(INS__P4, "'", "''") + "','" + Replace(INS__P5, "'", "''") + "','" + Replace(INS__P6, "'", "''") + "',)"
    INS.CommandType = 1
    INS.CommandTimeout = 0
    INS.Prepared = true
    INS.Execute()
    %>

    <%
    if(Request("ImeSlike") <> "") then INS__P7 = Request("ImeSlike")
    if(Request("Rubrika") <> "") then INS__P8 = Request("Rubrika")
    if(Request("SlikaM") <> "") then INS__P9= Request("SlikaM")
    if(Request("SlikaV") <> "") then INS__P10 = Request("SlikaV")
    %>
    <%
    set INS2 = Server.CreateObject("ADODB.Command")
    INS2.ActiveConnection = MM_FaksDipl_STRING
    INS2.CommandText = "INSERT INTO Fotoalbum (ImeSlike, Rubrika, SlikaM, SlikaV) VALUES ('" + Replace(INS__P7, "'", "''") + "', '" + Replace(INS__P8, "'", "''") + "', '" + Replace(INS__P9, "'", "''")+ "', '" + Replace(INS__P10, "'", "''") + "')"
    INS2.CommandType = 1
    INS2.CommandTimeout = 0
    INS2.Prepared = true
    INS2.Execute()
    %>



    <%
    if(Request("Zvok1") <> "") then INS__P11 = Request("Zvok1")
    if(Request("Zvok2") <> "") then INS__P12 = Request("Zvok2")
    if(Request("Zvok3") <> "") then INS__P13 = Request("Zvok3")
    if(Request("Zvok4") <> "") then INS__P14 = Request("Zvok4")
    if(Request("Zvok5") <> "") then INS__P15 = Request("Zvok5")
    if(Request("Zvok6") <> "") then INS__P16 = Request("Zvok6")
    %>
    <%
    set INS3 = Server.CreateObject("ADODB.Command")
    INS3.ActiveConnection = MM_FaksDipl_STRING
    INS3.CommandText = "INSERT INTO Zvocna (Zvok1, Zvok2, Zvok3, Zvok4, Zvok5, Zvok6) VALUES ('" + Replace(INS__P11, "'", "''") + "', '" + Replace(INS__P12, "'", "''") + "', '" + Replace(INS__P13, "'", "''") + "', '" + Replace(INS__P14, "'", "''") + "', '" + Replace(INS__P15, "'", "''") + "', '" + Replace(INS__P16, "'", "''") + "')"
    INS3.CommandType = 1
    INS3.CommandTimeout = 0
    INS3.Prepared = true
    INS3.Execute()
    %>
    <%
    Dim maxidFotoRS
    Dim maxidFRS_numRows

    Set maxidFotoRS = Server.CreateObject("ADODB.Recordset")
    maxiidFotoRS.ActiveConnection = MM_FaksDipl_STRING
    maxidFotoRS.Source = "SELECT MAX (Id) as idalbum FROM Fotoalbum"
    maxidFotoRS.CursorType = 0
    maxidFotoRS.CursorLocation = 2
    maxidFotoRS.LockType = 1
    maxidFotoRS.Open()

    maxidFotoRS_numRows = 0
    %>
    <%
    Dim maxidZvokRS
    Dim maxidZvokRS_numRows

    Set maxidZvokRS = Server.CreateObject("ADODB.Recordset")
    maxidZvokRS.ActiveConnection = MM_FaksDipl_STRING
    maxidZvokRS.Source = "SELECT MAX (Id) as idzvok FROM Zvocna"
    maxidZvokRS.CursorType = 0
    maxidZvokRS.CursorLocation = 2
    maxidZvokRS.LockType = 1
    maxidZvokRS.Open()

    maxidZvokRS_numRows = 0
    %>
    <%
    Dim maxidTextRS
    Dim maxidTextRS_numRows

    Set maxidTextRS = Server.CreateObject("ADODB.Recordset")
    maxidTextRS.ActiveConnection = MM_FaksDipl_STRING
    maxidTextRS.Source = "SELECT MAX (Id) as idtxt FROM Texti"
    maxidTextRS.CursorType = 0
    maxidTextRS.CursorLocation = 2
    maxidTextRS.LockType = 1
    maxidTextRS.Open()

    maxidTextRS_numRows = 0
    %>

    <%
    if(Request("Naslov") <> "") then INS__P17 = Request("Naslov")
    if(Request("Id_Naslov") <> "") then INS__P18 = Request("Id_Naslov")
    if(Request("Link") <> "") then INS__P19 = Request("Link")
    if(Request("Glava") <> "") then INS__P20 = Request("Id_Glava")
    if(maxiidFotoRS("idalbum") <> "") then INS__P21 = maxiidFotoRS("idalbum")
    if(maxidTextRS("idtxt") <> "") then INS__P22 = maxidTextRS("idtxt")
    if(maxidZvokRS("idzvok") <> "") then INS__P23 = maxidZvokRS("idzvok")
    if(Request("DatumDogodka") <> "") then INS__P24 = Request("DatumDogodka")
    'if(Request("DatumVnosa") <> "") then INS__P25 = Request("DatumVnosa")
    %>
    <%
    set INS4 = Server.CreateObject("ADODB.Command")
    INS4.ActiveConnection = MM_FaksDipl_STRING
    INS4.CommandText = "INSERT INTO Info (Naslov, Id_Naslov, Link, Id_Glava, IdFotoalbum, IDtext, IdZvocna, DatumDogodka) VALUES ('" + Replace(INS__P17, "'", "''") + "', '" + Replace(INS__P18, "'", "''") + "', '" + Replace(INS__P19, "'", "''") + "', '" + Replace(INS__P20, "'", "''") + "', '" + Replace(INS__P21, "'", "''") + "', '" + Replace(INS__P22, "'", "''")+ "', '" + Replace(INS__P23, "'", "''") + "', '" + Replace(INS__P24, "'", "''") + "')"
    INS4.CommandType = 1
    INS4.CommandTimeout = 0
    INS4.Prepared = true
    INS4.Execute()

    End If 'Request("ins")

  2. #2
    Join Date
    Jun 2004
    Location
    Kansas City, MO
    Posts
    1,607
    i have not looked over the code but you can do multiple inserts but youll need to replace the + with a &.

    Aside from that it should all work.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles