INSERTING data into MySQL using PHP Scripting

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Odisey
    New Member
    • May 2007
    • 14

    INSERTING data into MySQL using PHP Scripting

    OK -I can do this in PhpMyAdmin (hard coded) - so its not a DB problem.

    I am just getting started - thank you for the help.

    I am creating a page to INSERT user information into two tables.

    The first table is easy to accomplish. The user first and last name, e address, and they set a password - is INSERTED. VALUES pass and the user_id PRIMARY increments automatically - a record is stored.

    The second table is a credit card table. It is a tinyblob which is necessary. I am using a @salt also. The record sets, no problem. I SELECT the @salt, and then AES_ENCRYPT the input value using the salt to the table. As said no problem.

    Here is where I am not getting the logic. When I set the user table values, the PRIMARY key auto increments - right. I have created a column in the encode table (where the credit card info is stored) named user_id to act as the FOREIGN key INDEX. So that I can reference the credit card value through identifying the user's user_id in the users table. I do not know how to set the user_id in the FOREIGN key column in the second table to correlate, as it auto_increments in the first table. I have no idea how to send that same number to the second table.

    Thank you,
    Marc
  • Odisey
    New Member
    • May 2007
    • 14

    #2
    NO edit button...?

    I guess I need to use the $mysql_insert_i d function following the initial insert...don't know the syntx though. Any ideas?

    Marc

    Comment

    • pbmods
      Recognized Expert Expert
      • Apr 2007
      • 5821

      #3
      Originally posted by Odisey
      NO edit button...?
      YES edit button... but only for 5 minutes after you post ;)

      You'll be wanting to take a look at mysql_insert_id. Invoke mysql_insert_id after the target query, but before any other queries have a chance to execute.

      Comment

      Working...