Jump to content

Inserting in to two tables


Kemik

Recommended Posts

Hello,

 

I'm developing a league script. I'm creating the createteam.php file and want to create a record (the team) in the teams table and then create a record linking the team and the user who is creating the team (i.e. showing the user is in the team).

 

I'm using the following queries in a function...

 

The function

<?php $database->addNewClan($subname, $subtag, $subwebsite, $subhistory, $username) ?>

 

The queries

<?php    function addNewClan($name, $tag, $website, $history, $username){
      $time = time();
      $q = "INSERT INTO ".TBL_CLANS." VALUES ('$name', '$tag', '$website', '$history', $time)";
      return mysql_query($q, $this->connection);
   } ?>

 

Is there anyway to create a second query with the newly created teamid that is attached to the new team or would I have to select the record first to discover the teamid. The teamid field is an auto_increment in the database.

 

The new query needs to be along the lines of:

 

$q = "INSERT INTO ".TBL_CLAN_MEMBERS." VALUES ('teamid', '$username', $time)";

 

You can change the variable name if you wish. I would prefer keeping it all within the one function as the function is used in an IF statement...

 

<?php          if($database->addNewClan($subname, $subtag, $subwebsite, $subhistory)){
            return 0;  //New user added succesfully
         }else{
            return 2;  //Registration attempt failed
         } ?>

 

 

Thanks all.

Link to comment
https://forums.phpfreaks.com/topic/61735-inserting-in-to-two-tables/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.