HELP - insert data from one table to another with PHP and mySQL

Discussion in 'PHP' started by iJafari, Nov 4, 2009.

  1. #1
    I am trying to make a website for a volunteer group that needs people to register for events. I have a login script already, and I want to make it so that users can sign up for shifts without entering their personal information twice (I want the information to be taken from the 'users' table and added to a 'training' table). The following code is what I had so far:

    <?

    include"master_inc.php";
    $tDate = $_POST['tDate'];
    $tTime = $_POST['tTime'];
    $email = $_POST['email'];


    $query = "SELECT INTO training ('username', 'lastname', 'firstname', 'email', 'phone') FROM users WHERE email='$email'";

    // save the info to the database
    $results = mysql_query( $query );

    $query2 = "INSERT INTO training ('tDate','tTime') VALUES ( '$tDate', '$tTime')";

    // save the info to the database
    $results2 = mysql_query( $query2 );


    ?>

    I am not very good at PHP, so I don't always recognize things that I have done wrong very quickly. Is there another way to do this or am I just messing up something really simple?
     
    iJafari, Nov 4, 2009 IP
  2. javaongsan

    javaongsan Well-Known Member

    Messages:
    1,054
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    128
    #2
    I am assuming your table structure for training
    
    <?
    include"master_inc.php";
    $tDate = $_POST['tDate'];
    $tTime = $_POST['tTime'];
    $email = $_POST['email'];
    
    $query2 = "INSERT INTO training ('tusername', 'tlastname', 'tfirstname', 'temail', 'tphone', 'tDate','tTime') (Select username, lastname, firstname, email, phone, '$tDate', '$tTime' FROM users WHERE email='$email')";
    
    $results2 = mysql_query( $query2 );
    ?>
    
    Code (markup):
     
    javaongsan, Nov 4, 2009 IP