简体   繁体   中英

how to get data from one MySQL table and enter into another simultaneously

Please I am creating a page that will allow a user create a 'Team' by entering team name, team description and selecting members from his list of friends. I have sorted out the whole form issue hopefully.

Now, what I want to do is that once the user clicks 'Send Invite', a new team row is created in the 'teams' table and after this, the ids of his friends are collected and entered into a 'team members' table but I don't know to do this. This is what I did:

get_.php

if (isset($_POST['submit'])){

    $param = array(
    'tname' => $_POST['tname'],
    'tdesc' => $_POST['tdesc'],
    'owner' => $_SESSION['id'],

    );

    $sql="INSERT INTO teams (tname, tdesc, owner) VALUES (:tname, :tdesc, :owner)";

    if ($db->query($sql, $param)) {  

//How do I get the ids of his friends entered into the 'team members' table that has these columns

team_id = Will be the id of the newly created team members = ids of the friends.

Something like this

           team_id                     members

              1                           2
              1                           4
              1                           6
              1                           8

Thank you.

teams.php

    //The form to create a team
    <form action="get_.php" id="idea" method="post">
    <input type="text" id="tname" name="tname" placeholder="Enter Team Name" value="" class="">

    <textarea name="tdesc" style="width:400px; height:100px; resize:none;" placeholder="Purpose of Team"  class=""></textarea>

    <?php
        $sql = "SELECT i.*, m.* FROM addclique i JOIN members m ON m.id = i.clique_id WHERE adder_id = :id";
        $stmt = $db->query($sql, array('id' => $_SESSION['id']));

    ?>

    <select multiple="true" name="member[]"  val id="member" name="member" class="">
    <?php while($record = $stmt->fetch()) : ?>
       <option value="<?php $record['id'] ; ?>">  <?php echo $record['surname']; ?> <?php echo $record['firstname'] ; ?>  </option>
    <?php endwhile; ?>
    </select>


    <input type="submit" value="Send Invite" name="submit" class="btn btn-primary" />
    </form>

Try with

$tname  =$_POST['tname'];
$tdesc  =$_POST['tdesc'];
$owner  =$_POST['id'];


$receptor= strlen($Nombre) * strlen($correo) * strlen($asunto);
if($receptor >0){
$insertar=mysql_query("INSERT INTO contacto VALUES ('','$tname','$tdesc','$owner')");

if($insertar){
`enter code here`...
}

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM