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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.