Go Premium for a chance to win a PS4. Enter to Win

x
?
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
Medium Priority
?
407 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 39

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses four methods for overlaying images in a container on a web page
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 count occurrences of each item in an array.
Suggested Courses

877 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