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
374 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

This article discusses four methods for overlaying images in a container on a web page
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

752 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