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
356 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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Adding Extra Information box 4 26
Link SQL table to Webpage 9 39
PHP loop not working 4 33
SQL inner join confusion 15 22
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 …
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

747 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

11 Experts available now in Live!

Get 1:1 Help Now