How do you insert new records into multiple tables using the same unique primary key?

I’ve created a PHP site and MySQL server using a free app called XAMPP.  I have successfully created a form in Dreamweaver that will write data to a (name) table in the SQL database.  Here’s my question: How do you write to two (or more) tables in the same database and pass the same primary key to both tables?  In the SQL database, I defined the first field as ID and set it as the primary key with auto update.  So, when you insert a new record, it creates a unique primary key for that record.  In my form, I’m capturing info that needs to be stored to two tables at the same time; a Name table and Address table. Since the Name and Address tables use the ID field as the primary key, I believe I will need to pass the ID value from the Name table to the insert of the Address table to insure they both have the same primary key, right?

No. You probably need the primary key from one table to be a foreign key in the other tables. In any case, I believe you can use two methods to obtain the auto generated key. First with SQL:
http://dev.mysql.com/doc/refman/5.0/en/getting-unique-id.html
And the other using a PHP function:
http://us3.php.net/mysql_insert_id

Similar Messages

  • How to insert a UUID into multiple tables in the same form

    I am trying to insert a UUID into 2 different tables at the
    same time ie to let this be created in the form and then insert
    this ID into 2 linked tables in a database using Access.
    Does anybody have any suggestions on how to accomplish this?
    Thanks very much

    So you have one form that processes information for two
    tables, or do you
    have two forms (one for each table - except the UUID)?
    If it is one form just run two SQL insert statements. One for
    the primary
    table, then one for the related table.
    If it is two forms run the above two SQL statements then an
    update statement
    to finish filling the second table.
    Or am I completely misunderstanding the issue?
    Bryan Ashcraft (remove brain to reply)
    Web Application Developer
    Wright Medical Technology, Inc.
    Macromedia Certified Dreamweaver Developer
    Adobe Community Expert (DW) ::
    http://www.adobe.com/communities/experts/
    "weelco" <[email protected]> wrote in
    message
    news:esjtjj$qtc$[email protected]..
    > Thanks for your quick reply, and yes I do know how to do
    that however I
    > would
    > like to do this all in one form field so I would like to
    create the UUID
    > whith
    > the same form that also submits it to another table, is
    this possible or
    > do I
    > have to do that using multiple 'pages'?
    >

  • Inserting new records into database table at runtime

    Hi all ,
    How to insert new records into database table at runtime on click update?
    Thanks.

    Hi Sasikala,
    Just for your understanding am giving a sample code snippet which you can use to read the contents of your Table UI element & save the data on to your database. Suppose you have a button up on pressing which you want to read the data from your screens table & save on to the database then you can proceed as shown below:
    1) Obtain the reference of your context node.
    2) Fetch all the data present in your table into an internal table using methods of if_wd_context_node
    3) Use your normal ABAP logic to update the database table with the data from your internal table
    In my example I have a node by name SFLIGHT_NODE and under this I have the desired attributes from SFLIGHT. Am displaying these in an editable table & the user would press up on a push button after making the necessary changes to the tables data. I would then need to obtain the tables information & save on to the database.
    data: node_sflight           type ref to if_wd_context_node,
            elem_sflight           type ref to if_wd_context_element,
            lt_elements            type WDR_CONTEXT_ELEMENT_SET,
           stru_sflight           type if_main=>element_sflight_node,
           it_flights             type if_main=>elements_sflight_node.
    "   navigate from <CONTEXT> to <SFLIGHT_NODE> via lead selection
        node_sflight_node = wd_context->get_child_node( name = 'SFLIGHT_NODE'  ).
       lt_elements = node_sflight->get_elements( ).
    "   Get all the rows from the table for saving on to the database
        loop at lt_elements into elem_sflight.
          elem_sflight->get_static_attributes( importing static_attributes = stru_sflight ).
          append stru_sflight to it_flights.
        endloop.
    " Finally save the entries on to the database
        modify ZSFLIGHT99 from table it_flights.
        if sy-subrc eq 0.
    endif.
    However a word of caution here.... SAP doesn't ever recommend directly modifying the database through an SQL query. You would preferably make use of a BAPI for the same. Try go through Thomas Jung's comments in [here|modify the data base table which is comming dynamiclly;.
    Regards,
    Uday

  • How to insert new record into oracle table from GridView in VS2005.

    I need to insert records into Oracle10g table from VS2005 GridView using the Insert Method in Business Logic Class. The Update and Delete Methods are working fine. What's the best way out?

    How is it "not possible"?
    Either modify the Class for the new fields, or give the new fields default values (if applicable). If the type of an existing column has changed, then only the first option is available.
    Where's the problem?

  • How to insert new record into altered table

    I am using JDBC with MySQL. I altered existing table and want to insert new record using java class. But it is not possible.How to do?

    How is it "not possible"?
    Either modify the Class for the new fields, or give the new fields default values (if applicable). If the type of an existing column has changed, then only the first option is available.
    Where's the problem?

  • How can you develop photo galleries with multiple pages using the web module?

    Going through the web module I can see there are many options for developing a web page with a single collection of photos.  How can you develop a web site with multiple pages containing different categories of photos using the Lightroom web module?

    This thread will give you several ideas.
    Re: How do you embed a gallery into an existing website?

  • How do I insert  input data into anoracle table using C#

    Hi guys,
    I am new in the .NET arena and I am using Visual Studio 2005 Pro edition.. For instance I have 2 forms one being the main form which calls another to to insert captured text onto a form with the idea of passing it into the oracle database. I am failing to do that using C#. Where am I going wrong? Part of the code when I use actual values, data is written but when I want to write from input text from the form I get an Oracle message ORA-00936. A global connection is established in the first form.
    Here is the successful code:
    Try
    MyCmd.CommandText="insert into station (stn_abb,stn_no,stn_name)"+
    "values('MUT','0480','MUTARE')";
    Int rowsUpdated = MyCmd.ExecuteNonQuery();
    If (rowsUpdated == 0)
    MessageBox.Show("RECORD NOT WRITTEN");
    Else
    MessageBox.Show("RECORD WRITTEN TO TABLE");
    Txn.Commit();
    Here is the UNSUCCESSFUL code:
    Try
    MyCmd.CommandText = "insert into station (stn_abb,stn_no,stn_name)" +
    "values(@txtStnAbb.Text,@txtStnNo.Text,@txtName.Text)";
    Int rowsUpdated = MyCmd.ExecuteNonQuery();
    If (rowsUpdated == 0)
    MessageBox.Show("RECORD NOT WRITTEN");
    Else
    MessageBox.Show("RECORD WRITTEN TO TABLE");
    Txn.Commit();
    Regards,
    Ray.

    Hi,
    I assume that in the second example your intent is to use bind variables, but I dont see where you're actually binding any variables. Also, "@" is sqlserver syntax, Oracle's syntax is ":".
    Here's a complete example, hope it helps.
    Cheers
    Greg
    create table smallcol(col1 varchar2(5));
    using System;
    using System.Data;
    using Oracle.DataAccess.Client;
    using Oracle.DataAccess.Types;
    public class odpparams
         public static void Main()
              OracleConnection con = new OracleConnection("user id=scott;password=tiger;data source=orcl");
              con.Open();
              OracleCommand cmd = new OracleCommand("insert into testtab values(:1)",con);
    cmd.Parameters.Add(new OracleParameter("1",OracleDbType.Varchar2,4,"fred",ParameterDirection.Input));
    cmd.ExecuteNonQuery();
    Console.WriteLine("done, no errors");
    con.Dispose();
    }

  • How do you do a search for multiple occurences of the same word in a NOTE?

    How do you search for multiiple occurences of a word in NOTES?  I seem only to be able to find the first occurence and then it goes into a loop, never past the first occurence.

    I want to find all the same words in ONE NOTE. It is a very loong list and I want to find all cccurences of a specific word in that one NOTE when I do a search. I thought I had solved this earlier today but now I can't seem to repeat it. I type in word in the SEARCH box, select the NOTE and then it shows me the FIRST occurence in that note, but only the first,

  • Inserting an image into a table using the iPad?

    I am trying to make an evidence table in pages. I need to insert photographs into a table, next to the related statement. Is it possible to insert a photograph into the table on an iPad as I obviously don't have the 'command' button that others are using. If this is possible I want to be able to insert the picture as a predefined size?

    Hi,
    Yes, you can do this by using the Word Edit Cell VI under Report Generation>>Word Specific>>Word Tables in your block diagram functions pallette.  After creating a table, you can edit specific cells and send the file path of the image saved on your computer to that specific cell.  I put together an example that I've attached here as well to help you out with this.
    Regards,
    Austin S.
    National Instruments
    Academic Field Engineer
    Attachments:
    RGTWordImageInTable.vi ‏14 KB

  • How can i insert character data in a table using the report trigger

    well here is my query
    do_sql ('insert into report_trigger_details values(po report,before parameter)');
    i need to to insert data from within the report using the before parameter form trigger.Error is as follows:
    error: rep-1425,cant parse the statement,missing comma
    This error got removed by removing the space in ''po report" and before parameter"
    Now the error that i get is :ora-00984:column not allowed here
    Also i need to keep the spaces between the values while inserting data
    Please help!!!
    Thanks
    Edited by: 924271 on Mar 29, 2012 7:02 AM
    Edited by: 924271 on Mar 29, 2012 7:07 AM
    Edited by: 924271 on Mar 29, 2012 7:08 AM

    I know this isnt a great way of using query but its part of the assignment ,so any help will be greatly appreciated.
    Here it is again......
    function BeforePForm return boolean is
    segment2 varchar2(10);
    begin
         srw.message(001,'I just got executed first');
    srw.do_sql('select segment1 into :segment2 from xxmssl_po_headers_all');
    srw.do_sql('insert into report_trigger_details values(seq2.nextval,:segment2,''po report'',''before parameter form'',''po number is'')');
    srw.do_sql('commit');
    return (TRUE);
    end;
    the that i was getting earlier was resolved by using two single quotes....Now the error is....
    Error: error putting value in column....
    column 'segment2' may not be referenced by parameter triggers..
    The insert ran fine until I changed the above function as follows:
    function BeforePForm return boolean is
    segment2 varchar2(10);
    type_code varchar2(10);
    org_no number(4);
    begin
         srw.message(001,'I just got executed first');
    srw.do_sql('select segment1,type_lookup_code,org_id into :segment2,:type_code,:org_no from xxmssl_po_headers_all');
    srw.do_sql('insert into report_trigger_details values(seq2.nextval,:segment2,''po report'',''before parameter form'',''po number is'':segment2 '',type_code is'':type_code '',org_no is'':org_no )');
    srw.do_sql('commit');
    return (TRUE);
    end;
    When i ran it ,it started giving the above mentioned error.I reverted the changes back and recompiled my report but still getting the same error....
    Thanks in advance
    Edited by: 924271 on Mar 29, 2012 11:59 PM
    Edited by: 924271 on Mar 30, 2012 12:11 AM

  • How i can Insert selected records in database table using check box.

    Hi Friends,
    I have non database block, which displayed multiple records, now I add a Check Box to this block and now I want to insert the records in a database table which I checked. So when I press a button, all the checked records are inserted in the table.
    Please send me the code of this solution.
    Thanks in advance.
    Shahzad

    I have almost the exact scenario but instead of inserting into the DB, I want to find the Checked records and process them in PL/SQL script.
    I currently have a cursor that looks for all the checked records. It's only getting the first record, so I figured I need to loop through the block looking for checked records.
    Also can I save them to a temp or PL/SQL table to process later?

  • How do I insert new record and get results on a landing page

    how do I insert new record and get results on a landing page

    It's not clear from your post what you are asking. In a SQL database, you use the INSERT statement to insert a row into a table. You use the SELECT statement to retrieve rows. Here's some basic info on how to do that within PHP
    PHP MySQL Insert Into
    PHP MySQL Select

  • How do you insert a picture into another picture?

    How do you insert a picture into another picture.  For example, one person is missing from family photo & I'd like to insert that person's face.

    By using an external editor:
    In order of price here are some suggestions:
    Seashore (free)
    The Gimp (free)
    Graphic Coverter ($45 approx)
    Acorn ($50 approx)
    Pixelmator ($50 approx)
    Photoshop Elements ($75 approx)
    There are many, many other options. Search on MacUpdate. You can set Photoshop (or any image editor) as an external editor in iPhoto. (Preferences -> General -> Edit Photo: Choose from the Drop Down Menu.) This way, when you double click a pic to edit in iPhoto it will open automatically in Photoshop or your Image Editor, and when you save it it's sent back to iPhoto automatically. This is the only way that edits made in another application will be displayed in iPhoto.

  • How do I separate a PDF into multiple PDFs using Adobe PDF Pack?

    How do I separate a pdf into multiple pdfs using AdobePack?
    [Title edited to reflect actual product name... Mod]

    I do not find "AdobePack" when I look at the list of forums https://forums.adobe.com/welcome
    What is the exact name of the program you are using... Acrobat, or are you using the online version at Acrobat.com?
    ADDED... found Adobe PDF Pack (read only) so will move this message

  • How do you take off reseiving messages on multiple devices using the same apple account

    How do you take off reseiving messages on multiple devices using the same apple account?

    Go to Settings>Messages>Send and Receive on all but one device and add a unique email address on each device and delete the commone Apple ID email device
    If there is also an iPhone with iOS 6 associated with the Apple ID, uncheck the phone number on all but the phone.

Maybe you are looking for

  • Consume External Web Service (WSDL) in ABAP (Release 700) - Proxy Error

    Hi All, Have a requirement to Consume an External Web Service in ABAP. We have the WSDL for Ext. Web Service. Did some research and came across the link: http://help.sap.com/saphelp_nw2004s/helpdata/en/69/8a1e9553dc4baba6026a3db510cadb/content.htm Fi

  • Satellite C660d-A2k - How to increase display backlight using battery mode

    I bought a new laptop, installed all the drivers and it works. How to turn on the backlight? It only works when I charge the laptop. turn off when it goes off. If add the screen brightness to maximum and turn charging the screen becomes even brighter

  • Can anyone help me recover photos I have deleted from my ipod (& laptop)?

    Basically I am selling my laptop and so I thought I'd use the ipod as a means of storing my photos for future transfer to another laptop. So I synched it all, all fine, then I deleted half the photos from my laptop (to get it ready to sell) and conne

  • N73 - not displaying new messages

    I upgraded my n73's firmware about a month ago and i am on Vodafone. On Saturday my phone stopped displaying and vibrating when i received a new text message, it also doesn't display the little mail picture under the the operator name. However i've n

  • Why won't an MP3 file on my Mac play on the boombox?

    Hello, I tried to pair the Sony Bluetooth Boombox Model #ZSBTG900 with a new Macbook Pro (for the first time) with the boombox close to the computer & Bluetooth turned on. The proper words appear on the boom box display and the necessary blue light i