Page 1 of 2 1 2 LastLast
Results 1 to 15 of 19

Thread: insert data into multiple table

  1. #1
    Join Date
    Jul 2005
    Location
    kl
    Posts
    11
    Rep Power
    0

    insert data into multiple table

    hai.. kite nak tanya... bley tak nak masukkan data ke dalam byk table dlm satu borang menggunakan coldfusion.. klu bley,tlg tunjuk ajar..
    trimas...

  2. #2
    Join Date
    Jul 2005
    Location
    KL
    Posts
    68
    Rep Power
    175
    Easy. Just use 2 or more SQLs to insert into 2 or more tables.

  3. #3
    Join Date
    Jul 2005
    Location
    kl
    Posts
    11
    Rep Power
    0
    kite dah cube guna 2 sql yg berbeza tp ader error.. mcm mana ek?
    plzzz ader sesape leh tolong???

    nie sql nye...

    <cfquery name="add_peminjam" datasource="maklumat" username="" password="">
    INSERT INTO peminjam (nama, bahagian) VALUES ('#Form.nama#', '#Form.bahagian#')
    </cfquery>

    <cfquery name="add_tarikh" datasource="maklumat" username="" password="">
    INSERT INTO pinjam (tarikhpinjam, tarikhjangkapulang) VALUES ('#Form.tarikhpinjam#', '#Form.tarikhjangkapulang#')
    </cfquery>



    yg nie plak error nye..

    Error Occurred While Processing Request
    Error Diagnostic Information
    ODBC Error Code = 23000 (Integrity constraint violation)


    [Microsoft][ODBC Microsoft Access Driver] You cannot add or change a record because a related record is required in table 'peminjam'.



    The error occurred while processing an element with a general identifier of (CFQUERY), occupying document position (11:1) to (11:73).


    Date/Time: 07/25/05 15:27:15
    Browser: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; (R1 1.5))
    Remote Address: 127.0.0.1
    HTTP Referrer: http://localhost/baru/pinjam.cfm

  4. #4
    Join Date
    Jul 2005
    Location
    KL
    Posts
    68
    Rep Power
    175
    Oh, this is due to "Integrity constraint violation". Your pinjam table has 2 fields only? Most likely it has more fields and these other fields (especially the field that corresponds to the primary key "nama" in "peminjam") have to be updated also. If you update 2 fields only, then out the error...

    Cheers.

  5. #5
    Join Date
    Jul 2005
    Location
    kl
    Posts
    11
    Rep Power
    0
    adakah u maksud kan kena tambah atribut 'nama' dlm table pinjam?

  6. #6
    Join Date
    May 2002
    Location
    Kuala Lumpur, Malaysia
    Posts
    36
    Rep Power
    0

    Structure

    Juz show us your table structure here

  7. #7
    Join Date
    Jul 2005
    Location
    kl
    Posts
    11
    Rep Power
    0

    table

    ok.. nie die table kite...

    pinjam (nopinjam,nopeminjam,nosiriinventori,tarikhpinjam, tarikhjangkapulang,tarikhpulang)

    peminjam(nopeminjam,nama,bahagian)

    klu kite guna sql mcm kat atas tuh mmg error tapi data bley masuk dlm table peminjam sahaja.. nape ekk???

  8. #8
    Join Date
    Jul 2005
    Location
    KL
    Posts
    68
    Rep Power
    175
    Data is not being inserted into "pinjam" - this is because of "Integrity constraint violation".
    I guess nopeminjam is an autonumber field? You need to get this autonumber value and insert into pinjam.nopeminjam. That should solve the problem.

  9. #9
    Join Date
    Jul 2005
    Location
    kl
    Posts
    11
    Rep Power
    0

    ok

    ok,nopeminjam mmg autonumber... kat mana nak letak coding insert into pinjam.peminjam tuh?

  10. #10
    Join Date
    May 2002
    Location
    Kuala Lumpur, Malaysia
    Posts
    36
    Rep Power
    0

    MMmmMMMmmmm

    INSERT INTO peminjam (nama, bahagian) VALUES ('#Form.nama#', '#Form.bahagian#')

    INSERT INTO pinjam (tarikhpinjam, tarikhjangkapulang) VALUES ('#Form.tarikhpinjam#', '#Form.tarikhjangkapulang#')

    pinjam (nopinjam,nopeminjam,nosiriinventori,tarikhpinjam, tarikhjangkapulang,tarikhpulang)

    peminjam(nopeminjam,nama,bahagian)


    Sounds like you have a foregin key relationship set up, and you are not supplying a valid record id.

    If you set pinjam..nopeminjam = autonumber, relationship between pinjam..nopeminjam and peminjam..nopeminjam will b revoke due to there were no matching id between pinjam.nopeminjam and peminjam.nopeminjam.

    For table..pinjam, set nopinjam to primarykey and autonumber, then drag the id from peminjam.nopeminjam and insert it back to your pinjam..nopeminjam (do not put pinjam.nopeminjam as autonumber).

    e.g.

    INSERT INTO peminjam (nama, bahagian) VALUES ('#Form.nama#', '#Form.bahagian#')

    then

    select @nopeminjam from peminjam order by nopeminjam desc

    then

    INSERT INTO pinjam (nopeminjam, tarikhpinjam, tarikhjangkapulang) VALUES (@nopeminjam,'#Form.tarikhpinjam#', '#Form.tarikhjangkapulang#')

    end

  11. #11
    Join Date
    Jul 2005
    Location
    kl
    Posts
    11
    Rep Power
    0

    aiiyakk...

    ok, nie semua table & atribut yg sy ader

    peminjam (nopeminjam (autonumber & primary key), nama, bahagian)

    pinjam (nopinjam (autonumber & primary key), nopeminjam, nosiriinventori, tarikhpinjam, tarikhjangkapulang, tarikhpulang)

    inventori (nosiriinventori (primary key), jenis, model, kodhartamodal, harga)

    aksesori (nosiri (primary key), nosiriinventori, jenis, model)

    1st, bley tak kite nak tau... ape fungsi "@" pd @nopeminjam tuh..

    2nd... sql yg sy wat still tak jadi... ader error

    <cfquery name="add_peminjam" datasource="maklumat" username="" password="">
    INSERT INTO peminjam (nama, bahagian) VALUES ('#Form.nama#', '#Form.bahagian#')
    </cfquery>

    <cfquery name="add_nopeminjam" datasource="maklumat" username="" password="">
    select @nopeminjam from peminjam order by nopeminjam desc
    </cfquery>

    <cfquery name="add_tarikh" datasource="maklumat" username="" password="">
    INSERT INTO pinjam (nopeminjam, tarikhpinjam, tarikhjangkapulang) VALUES (@nopeminjam,'#Form.tarikhpinjam#', '#Form.tarikhjangkapulang#')
    </cfquery>

    yg nie plak errornye

    Error Occurred While Processing Request
    Error Diagnostic Information
    ODBC Error Code = 07001 (Wrong number of parameters)


    [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.

    Hint: The cause of this error is usually that your query contains a reference to a field which does not exist. You should verify that the fields included in your query exist and that you have specified their names correctly.


    The error occurred while processing an element with a general identifier of (CFQUERY), occupying document position (11:1) to (11:77).


    Date/Time: 07/27/05 12:24:37
    Browser: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; (R1 1.5); FDM)
    Remote Address: 127.0.0.1
    HTTP Referrer: http://localhost/baru/pinjam.cfm

  12. #12
    Join Date
    May 2002
    Location
    Kuala Lumpur, Malaysia
    Posts
    36
    Rep Power
    0

    Talking

    Dear azmaliya,

    What i mean is that you need to drag the last noPeminjam from your peminjam table and put it back to your pinjam table.

    As for select @nopeminjam from peminjam order by nopeminjam desc, @nopeminjam is something that you need to declare and put it back into your PINJAM table.

    BTW, for your information @ = SQL StoredProcedure/Trigger language, which we use that to declare something, it is nothing to do with you CFM

  13. #13
    Join Date
    Jul 2005
    Location
    KL
    Posts
    68
    Rep Power
    175

  14. #14
    Join Date
    Jul 2005
    Location
    kl
    Posts
    11
    Rep Power
    0
    jgn lah gelak kan kite... kite baru nak blaja tauu...

  15. #15
    Join Date
    Jul 2005
    Location
    kl
    Posts
    11
    Rep Power
    0
    hello there.... it's me again.. still tak dpt lagi lah.. tlg lah kite....

    kali nie kite try wat mcm nie plak.. tp tak jadi jgk..

    <cfquery name="add_peminjam" datasource="maklumat" username="" password="">
    INSERT INTO peminjam (nama,bahagian) VALUES ('#Form.nama#','#Form.bahagian#');
    select @nopeminjam from peminjam order by nopeminjam desc
    </cfquery>

    <cfquery name="add_tarikh" datasource="maklumat" username="" password="">
    INSERT INTO pinjam (nopeminjam,tarikhpinjam,tarikhjangkapulang) VALUES ('#add_peminjam.nopeminjam#','#Form.tarikhpinjam#' , '#Form.tarikhjangkapulang#')
    </cfquery>


    Error Occurred While Processing Request
    Error Diagnostic Information
    ODBC Error Code = 37000 (Syntax error or access violation)

    [Microsoft][ODBC Microsoft Access Driver] Characters found after end of SQL statement.

    The error occurred while processing an element with a general identifier of (CFQUERY), occupying document position (8:1) to (8:75).

    Date/Time: 07/29/05 11:53:08
    Browser: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; (R1 1.5); FDM)
    Remote Address: 127.0.0.1
    HTTP Referrer: http://localhost/baru/pinjam.cfm

Page 1 of 2 1 2 LastLast

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Y tak bole access my thread previously...(insert multiple row)
    By emnieysh in forum Website Programming
    Replies: 1
    Last Post: 10-04-2008, 10:30 AM
  2. Tolong saya!!(Cam ne nak insert multiple record in sql)
    By emnieysh in forum Website Programming
    Replies: 11
    Last Post: 08-04-2008, 03:08 PM
  3. Data xleh masuk dlm table..
    By sweets in forum Website Programming
    Replies: 10
    Last Post: 30-03-2007, 02:57 PM
  4. Multiple data
    By koisempoi in forum Website Programming
    Replies: 5
    Last Post: 06-12-2004, 10:51 AM
  5. insert multiple data
    By vash in forum Website Programming
    Replies: 4
    Last Post: 28-04-2004, 02:48 PM

Posting Permissions

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

Search Engine Optimization by vBSEO 3.5.0 RC1 PL1

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112