Page 2 of 2 FirstFirst 1 2
Results 16 to 19 of 19

Thread: insert data into multiple table

  1. #16
    Join Date
    Jul 2005
    Location
    KL
    Posts
    68
    Rep Power
    172
    Myself sudah pening ler...

    Try the codes below. However, I have not program in coldfusion for years... so, there might be syntax error.

    Code:
    <cfquery name="add_peminjam" datasource="maklumat" username="" password="">
    INSERT INTO peminjam (nama,bahagian) VALUES ('#Form.nama#','#Form.bahagian#')
    </cfquery>
    
    <cfquery name="bla" datasource="maklumat" username="" password="" maxRows="1">
    select nopeminjam from peminjam order by nopeminjam desc
    </cfquery>
    
    <cfoutput query="bla">
    <cfset ddd = "#nopeminjam#">
    </cfoutput>
    
    <cfquery name="add_tarikh" datasource="maklumat" username="" password="">
    INSERT INTO pinjam (nopeminjam,tarikhpinjam,tarikhjangkapulang) VALUES ('#ddd#','#Form.tarikhpinjam#' , '#Form.tarikhjangkapulang#')
    </cfquery>

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

    horeyyyy

    horey... kite dah berjaya melaksanakan misi... terima kasih kepada semua yg membantu ( jacky & victor )... kite gunakan coding yg jacky bg tuh... next time klu kite tak tau wat, kite tanya lagi ek... trimasss...

  3. #18
    Join Date
    Jul 2005
    Location
    KL
    Posts
    68
    Rep Power
    172

  4. #19
    Join Date
    Nov 2001
    Location
    Johor
    Posts
    772
    Rep Power
    231
    utk sistem yg compatible database structure mesti bagus.
    ni sample guna mysql database.

    ########################## DATABASE #######################################

    table peminjam
    -----
    id = varchar 35 (null = no) primary
    no_kp = varchar 30 (null = no) primary
    nama = varchar 100 (null = yes)
    bahagian = varchar 35 (null = no)
    regdate = datetime (null = yes)


    table bahagian
    -----
    id = varchar 35 (null = no) primary
    bahagian = varchar 100 ( null = no)


    table buku
    -----
    id = varchar 35 (null = no) primary
    nama_buku = varchar 150 (null = no)
    isbn = varchar 20 (null = yes)
    unit = int 5 (null = no, default 1)


    table pinjam/record transaksi
    -----
    id = varchar 35 (null = no) primary
    book_id = varchar 35 (null = no)
    peminjam = varchar 35 (null = no)
    date_pinjam = date (null = no)
    date_pulang = date (null = yes)
    date_transaksi = datetime (null = yes)
    status = int (null = yes, default = 1) (0 = not return / 1 = return)


    ########################## FORM ###########################################
    Code:
    <!---
    *
    * form pinjam if (user baru prom user regform)
    *
    --->
    <cset userid = createuuid()>
    
    <cfquery name="qryDepartment" datasource="#request.conf.dsn#">
    	select * from [table bahagian] where id = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#form.bahagian#">
    </cfquery>
    
    <cfquery name="qryAddUser" datasource="#request.conf.dsn#">
    	insert into [table peminjam] (id,no_kp,nama,bahagian,regdate) values(
    	<cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#userid#">,
    	<cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#form.no_kp#">,
    	<cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#form.nama#">,
    	<cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#qryDeparment.id#">,
    	#createodbcdate(now())#	
    	)
    </cfquery>
    
    
    <!---
    *
    * form pinjam else (user sedia ada)
    *
    --->
    <cfquery name="qryUser" datasource="#request.conf.dsn#">
    	select id from [table peminjam] where no_kp = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#form.no_kp#">
    </cfquery>
    
    <cfquery name="qryBook" datasource="#request.conf.dsn#">
    	select unit from [table buku] where id = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#form.book_id#">
    </cfquery>
    
    <cfif qryBook.unit gt 0>
    
    	<cfquery name="qryBook" datasource="#request.conf.dsn#">
    		update [table buku] set unit = (unit - 1) where id = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#form.book_id#">
    	</cfquery>
    
    
    	<cfquery name="qryTrans" datasource="#request.conf.dsn#">
    		insert into [table transaksi] (id,book_id,peminjam,date_pinjam,date_pulang,date_transaksi) values(
    		<cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#createuuid()#">,
    		<cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#form.book_id#">,
    		<cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#form.no_kp#">,
    		<cfqueryparam cfsqltype="CF_SQL_DATE" value="#createodbcdate(form.date_pinjam)#">,
    		<cfqueryparam cfsqltype="CF_SQL_DATE" value="#createodbcdate(form.date_pulang)#">,
    		#createodbcdate(now())#	
    		)
    	</cfquery>
    
    <cfelse>
    	sorry buku dah takde. org dah pinjam.
    </cfif>
    I hate when:

    vBulletin Message:
    Sorry! The administrator has specified that users can only post one message every 60 seconds

Page 2 of 2 FirstFirst 1 2

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