Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

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
?
395 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
Independent Software Vendors: 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

715 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