0

I have a piece of code:

 // trainer query
  $query = "INSERT INTO ".TBL_USERS." SET username = :username, password = :password, alliance = :alliance, avatar = :avatar, gender = :gender,  usersalt = :usersalt, userid = 0, userlevel = $ulevel, email = :email, timestamp = $time, actkey = :token, ip = '$userip', regdate = $time"; 
  $stmt = $this->connection->prepare($query);
  return $stmt->execute(array(':username' => $username, ':password' => $password, ':usersalt' => $usersalt, ':alliance' => $alliance, ':avatar' => $avatar, ':gender' => $gender, ':email' => $email, ':token' => $token));

  // pokemon query
   $query2 = "INSERT INTO ".TBL_POKEMON." SET Trainer = :trainer, OTrainer = :otrainer, Pokemon = :pokemon, shiny = :shiny, Level = :level, Nlevel = :nlevel, EXP = :exp, EXPN = :expn, HP = :hp, mhp = :mhp, Gender = :gender, Item = :item, Attack1 = :attack1, Attack2 = :attack2, Attack3 = :attack3, Attack4 = :attack4"; 
  $stmt2 = $this->connection->prepare($query2);
  return $stmt2->execute(array(':trainer' => $username, ':otrainer' => $username, ':pokemon' => $starter, ':shiny' => $shiny, ':level' => 10, ':nlevel' => 11, ':exp' => 1001, ':expn' => 1331, ':hp' => $hp2, ':mhp' => $hp2, ':gender' => $gender, ':item' => None, ':attack1' => $attack1, ':attack2' => $attack2, ':attack3' => $attack3, ':attack4' => $attack4));

Now I want both queries to be submitted into the database however, only the trainer query seems to be working. If I remove the trainer query and leave the pokemon query, the pokemon query works. But if I use them both together, they don't seem to be working... am I doing something wrong?

Edit: When I used them both together, I used stmt2 and query2, and I even tried both of them as stmt and query.. so I'm really stumped.

Edited by zerotolerance

3
Contributors
2
Replies
13
Views
5 Years
Discussion Span
Last Post by jkon
0

Now I want both queries to be submitted into the database however, only the trainer query seems to be working. If I remove the trainer query and leave the pokemon query, the pokemon query works. But if I use them both together, they don't seem to be working... am I doing something wrong?

For the pokemon query you INSERT $username and $hp2 twice at the same time.

Try to rename both of them and INSERT into a different column. Instead of $username try $username1 & $username2 and for $htp2 try $htp1 and $htp2

So your pokemon query should look like this:

// pokemon query
$query2 = "INSERT INTO ".TBL_POKEMON." SET Trainer = :trainer, OTrainer = :otrainer, Pokemon = :pokemon, shiny = :shiny, Level = :level, Nlevel = :nlevel, EXP = :exp, EXPN = :expn, HP = :hp, mhp = :mhp, Gender = :gender, Item = :item, Attack1 = :attack1, Attack2 = :attack2, Attack3 = :attack3, Attack4 = :attack4";
$stmt2 = $this->connection->prepare($query2);
return $stmt2->execute(array(':trainer' => $username1, ':otrainer' => $username2, ':pokemon' => $starter, ':shiny' => $shiny, ':level' => 10, ':nlevel' => 11, ':exp' => 1001, ':expn' => 1331, ':hp' => $hp1, ':mhp' => $hp2, ':gender' => $gender, ':item' => None, ':attack1' => $attack1, ':attack2' => $attack2, ':attack3' => $attack3, ':attack4' => $attack4));

This should work. I don't see anything interfering.

Edited by LastMitch: grammer

0

To be honest that is a very bad code using PDO, why the table names are constants ? . Why that isn’t a data worker with sql statements and functions to work with them ? Why , because you use the same PDO flow don’t you have a PDO child DB class ? . Why don’t you clarify the values with prepared statements marks '?' ?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.