Solved

How can i get the last insert record ID from table 1 and put it into table 2 in same page?

Posted on 2011-03-24
6
357 Views
Last Modified: 2013-12-13
Hi all ,

My database contents 3 table

Table 1 Name : Lesson   ( structure for table ) :

`lessonId` int(11) NOT NULL AUTO_INCREMENT, ( PRIMARY KEY )
`lessonName` varchar(50) COLLATE utf8_unicode_ci NOT NULL,

Table 2 Name : Media   ( structure for table ) :
`mediaId` int(11) NOT NULL AUTO_INCREMENT, ( PRIMARY KEY )
 `mediaName` varchar(50) COLLATE utf8_unicode_ci NOT NULL,

Table 3 Name : Link ( structure for table ) :
`link` varchar(1000) COLLATE utf8_unicode_ci DEFAULT NULL,
 `lessonId` int(11) NOT NULL, (FOREIGN KEY )
 `mediaId` int(11) NOT NULL, (FOREIGN KEY )

we have relationship between :
1 -  lesson.lessonId ( PRIMARY KEY ) and link.lessonId (FOREIGN KEY )
2 - media,mediaId ( PRIMARY KEY ) and link.mediaId (FOREIGN KEY )

I am use Dreamweaver CS5 i want to make insert lesson page contents :

1- insert lesson name in text field for example :Lesson One
2 - let user select Media Name from menu for example : (Video_Sound _Text)
3 - insert link in text field for each mediaName in the same lesson

( Insert links fo all type in the same lesson)

How can i Dow this in dreamweaverCS5 and can i get the last insert lesson.lessonId and put in in link.lessonId in the same page ?

Thanks for all .

0
Comment
Question by:harabie2
6 Comments
 
LVL 3

Expert Comment

by:sbickerstaff
ID: 35206573
What database are you using? MySQL?
0
 
LVL 38

Expert Comment

by:Aaron Tomosky
ID: 35206590
0
 
LVL 3

Expert Comment

by:sbickerstaff
ID: 35206766
the reason i asked for the db being used is that yes, this mysql_insert_id will work well and I've used it a lot myself
i.e.

mysql_query("INSERT INTO tbltest(field1, field2) VALUES ('data1','data2');")
$lastid = mysql_inset_id();

but if postgres is the db, then there is no postgres equivalent of mysql_insert_id().
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Expert Comment

by:sbickerstaff
ID: 35206780
sorry, type:

$qryinsert = mysql_query("INSERT INTO tbltest(field1, field2) VALUES ('data1','data2');")
$lastid = mysql_insert_id();

Open in new window

0
 

Author Comment

by:harabie2
ID: 35206894
Data base Mysql

how can i make this in dreamweaver ?
0
 
LVL 70

Accepted Solution

by:
Jason C. Levine earned 500 total points
ID: 35210900
For this purpose, Dreamweaver is just an editor.  The internal code-writing behaviors will not allow you to do mysql_insert_id(), you have to either purchase another extension or learn enough about PHP to know where to the line given to you by sbickerstaff ($lastid = mysql_insert_id();)

Once you have $lastid set, you just use that value with another Insert query to add it to table 2.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

4 Experts available now in Live!

Get 1:1 Help Now