Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Finding the key of a row just added

Posted by enquirer (enquirer), 12 April 2005
I want to add a row to a table and then add other rows to another table that can be joined to that original row.  How do I find the row number that MySQL used?



Posted by admin (Graham Ellis), 12 April 2005
The last_insert_id function is the vital link that you're looking for. For example, if I wanted to find the entry_id of the most recently added post to The Horse's Mouth, I would write

select entry_id from mt_entry where entry_id = last_insert_id()


Posted by michelle (michelle), 12 April 2005
Thanks graham! I got the most of the parts working!
On the other hand , could I use this for updating the another table(materials in my case)? That bit doesnt quite work so far (updating the main one-workrecord table is working well). Thank you.

Posted by michelle (michelle), 12 April 2005
//Here is the sript that I wrote in save_updates() for update another table;
// Replace Name and Quantity in materials table
// (to be added)

$mid=$_REQUEST['mid'];
$Name=$_REQUEST['Name'];
$Quantity = $_REQUEST['Quantity'];

{$qr="UPDATE materials SET Name='$Name', Quantity='$Quantity' WHERE mid = '$mid'";
mysql_query($qr);
echo "$qr";
echo 'Done!';}

after I echo the query, then it shows message like;

UPDATE materials SET Name='', Quantity='' WHERE mid = ''

which shows no VALUES are updated even I try to request the values using $_REQUEST like above. Why??  

Posted by admin (Graham Ellis), 12 April 2005
Are you sure that the values that you're saving in the database are coming from the previous form ... which is implied by your use of $_REQUEST.  Perhaps they're in $_SESSION or somewhere else (e.g. in a row that you've just read back).  Try printing out the values of these variable and I would kinda bet they're wrong ... and never get into the UPDATE command

Posted by michelle (michelle), 13 April 2005
Sorry Graham, I didn't quiet follow you. I did print out the values of these variable instead using $ in update query and it works and I also check the values in html source of previous form(after click 'view' button) and contain the correct values inside as well. So I persume that the values are coming from the previous form?

Posted by michelle (michelle), 13 April 2005
Graham, an new interesting things happened that I found the name of the materials is defined as <inpur name=${field}_$rowcount> which is not match the name I request as $field only, then I delete the _$rowcount function, the update is working, but the update of workrecord table don't work! Why?
Thank you


Posted by michelle (michelle), 13 April 2005
haha, problem has been worked out!  . thanks for your tips Graham.  

Posted by admin (Graham Ellis), 13 April 2005
Glad it's sorted. I left home at about 5 this morning (for Harlow) and I'm just back on line now ... nice to find an "I've got it sorted"  

Posted by michelle (michelle), 13 April 2005
haha Thanks. You are working too hard! Take a good rest tonight. I was very very happy when I solved the problem too.  However, I still got two more tasks to do-- delete and report! It's not end yet and I will continue working hard.  Anyway, I go back to work now. Talk to you very soon with some  Q ......



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho