Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 7 of 7
  1. #1
    Junior Member Jahaziel Echenique's Avatar
    Join Date
    Feb 2012
    Location
    Central Islip, New York
    Posts
    16
    Member #
    30759
    Good afternoon,
    I'm trying to figure out a code to let me grab the ID created by the first mysql_query.. and insert it into the second one. userslogin is creating a id with auto increments and i need to transfer it into usersinfo. The code is bellow

    mysql_query("INSERT INTO userslogin VALUES (' ','$getuser','$password','$getemail' ,'0', '$code' ,'$date')");

    mysql_query("INSERT INTO 'usersinfo' ('id') (SELECT 'id' FROM 'userslogin' WHERE username='$getuser')");

    mysql_query("INSERT INTO usersinfo VALUES (' ','$getfname','$getmname','$getlname')");

  2.  

  3. #2
    Junior Member Jahaziel Echenique's Avatar
    Join Date
    Feb 2012
    Location
    Central Islip, New York
    Posts
    16
    Member #
    30759
    I really expected a couple of answers by now =/

  4. #3
    Senior Member Webzarus's Avatar
    Join Date
    May 2011
    Location
    South Carolina Coast
    Posts
    3,322
    Member #
    27709
    Liked
    770 times
    You've got 3 insert statements...

    Since the ID is auto increment and created when the record is created, there is no what to know what that is without a select statement...

    Either a select statement outright to pull all the user data ( based on username ). Or an insert statement with a select sub statement to get the data.

    Since you'll be using the username... You should probably have a procedure before the original statement to check and validate the username is not already in use.

    I'm sure ther are many ways to do this... This would just my preferred way of doing it.

  5. #4
    Junior Member Jahaziel Echenique's Avatar
    Join Date
    Feb 2012
    Location
    Central Islip, New York
    Posts
    16
    Member #
    30759
    I have a if statement already to check if the username is in use. In userslogin the id is auto increment but not in usersinfo. I'm not entirely understanding what you mean.

    mysql_query("INSERT INTO 'usersinfo' ('id') (SELECT * FROM 'userslogin' WHERE username='$getuser')");
    Is that what you mean?

  6. #5
    Senior Member Webzarus's Avatar
    Join Date
    May 2011
    Location
    South Carolina Coast
    Posts
    3,322
    Member #
    27709
    Liked
    770 times
    Yup... Or something similar

    FYI... I'm just teaching myself the php MySQL syntax ... But the SQL part is pretty similar to SQL that I've been using on oracle for many years, and the logic is the same...

    Don't know yet if you can do sub commands like that with MySQL... But they probably have something very similar... ( I'm finding out ).. But all the basics are the same... Insert/update/delete...

  7. #6
    Junior Member Jahaziel Echenique's Avatar
    Join Date
    Feb 2012
    Location
    Central Islip, New York
    Posts
    16
    Member #
    30759
    I believe I found a article that lead me to do something like this but wasn't sure on how to implement it. I will try it when i get home as i didn't leave my laptop on to remote in or set up the website in a free hosting..(as of yet)
    Thanks though. I just recently started to learn mysql too and php as well its been a adventure.

  8. #7
    Senior Member Webzarus's Avatar
    Join Date
    May 2011
    Location
    South Carolina Coast
    Posts
    3,322
    Member #
    27709
    Liked
    770 times
    In oracle, I would a actually create a procedure to copy the data... Then just call the procedure... I think procedures can be done if you have access to console... Just not sure if they can be done on MySQL DB's hosted on shared environments.

    I'll look into it and see.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 11:57 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com