entering data into two tables when a user registers

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jscrinc
Forum Newbie
Posts: 5
Joined: Fri May 14, 2010 6:59 am

entering data into two tables when a user registers

Post by jscrinc »

Hi, I need to know how I can insert data into two tables when a user registers.

Problem

When a user registers, data is inputted into the users table, thats there name, username password etc, but now i want to make another separate table, which will feature even more registration options, such as their favorite games, website, other emails etc.

The thing is how would i make a blank field in this table while the user registers, so when it comes updating that setting, its just a simple update query.

Here is the insert code:

Code: Select all

 function addNewUser($username, $password, $email, $userid, $name, $bio, $sims3id, $sporeid, $citiesxlid, $sims3, $sims3coll, $sims3wa, $sims3hels, $sims3wt, $sims3cas, $spore, $sporec_c, $sporega, $sporecc, $citiesxl){
	     $avatar = 'http://jscrgaming.co.uk/images/d4_temp/space/avatars/default.jpg';
      $time = time();
      /* If admin sign up, give admin user level */
      if(strcasecmp($username, ADMIN_NAME) == 0){
         $ulevel = ADMIN_LEVEL;
      }else{
         $ulevel = USER_LEVEL;
      }
	  
      $q = "INSERT INTO ".TBL_USERS." VALUES ('$username', '$password', '$userid', $ulevel, '$email', $time, '$name',  '$bio', '$sims3id', '$sporeid', '$citiesxlid', '0', '$sims3', '$sims3coll', '$sims3wa', '$sims3hels', '$sims3wt', '$sims3cas', '$spore', '$sporecandc', '$sporega', '$sporecc', '$citiesxl', '$avatar')";

	  return mysql_query($q, $this->connection);
	  
   }
and here is the code i thought would work:

Code: Select all

function addNewUser($username, $password, $email, $userid, $name, $bio, $sims3id, $sporeid, $citiesxlid, $sims3, $sims3coll, $sims3wa, $sims3hels, $sims3wt, $sims3cas, $spore, $sporec_c, $sporega, $sporecc, $citiesxl){
	     $avatar = 'http://jscrgaming.co.uk/images/d4_temp/space/avatars/default.jpg';
      $time = time();
      /* If admin sign up, give admin user level */
      if(strcasecmp($username, ADMIN_NAME) == 0){
         $ulevel = ADMIN_LEVEL;
      }else{
         $ulevel = USER_LEVEL;
      }
	  
      $q = "INSERT INTO ".TBL_USERS." VALUES ('$username', '$password', '$userid', $ulevel, '$email', $time, '$name',  '$bio', '$sims3id', '$sporeid', '$citiesxlid', '0', '$sims3', '$sims3coll', '$sims3wa', '$sims3hels', '$sims3wt', '$sims3cas', '$spore', '$sporecandc', '$sporega', '$sporecc', '$citiesxl', '$avatar')";
	  
	  //fill the user game database with blank data
	  $sql = "INSERT INTO user_games (username)
	  values ('$username')";
	  
	  return mysql_query($q, $this->connection);
	  return mysql_query($sql, $this->connection);
   }
   

So if anyone would help, it would be very hellpful indeed lol.

James

fyi, you may need explain ur answer, as im not always able to understand, still a newbie at this xD
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

Re: entering data into two tables when a user registers

Post by yacahuma »

the correct way will be to create a transaction. php adodb support transactions. I dont use mysql_* calls anymore. If you ever have to change databases you will regret it.
Post Reply