Jump to content

Query help


zerotolerance

Recommended Posts

Hi,

 

So I have this piece of code:

 

// getting the pokemon status
     $pokemonsql = $this->connection->query("SELECT * FROM ".TBL_POKEDEX." WHERE pokemon = '$starter'");
     while($pokemonrow = $pokemonsql->fetch()) {
        $hp1 = ($pokemonrow["baseHP"]/10)/2;
        $hp2 = ROUND($hp1)*10;
        $attack1 = $pokemonrow["attack1"];
        $attack2 = $pokemonrow["attack2"];
        $attack3 = $pokemonrow["attack3"];
        $attack4 = $pokemonrow["attack4"];
        $gender_random = RAND(1,2); 
        if($gender_random == "1") {
            $pokemon_gender = "Male"; 
            } 
        if($gender_random == "2") { 
            $pokemon_gender = "Female"; 
            }
     // everyone should have a chance of getting a shiny starter 
        $shiny_random = RAND(1,40);
        if($shiny_random == "40" ) {
            $shiny = "Yes";
        } else {
            $shiny = "No";
        }
        }
     
      // 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
      $query = "INSERT INTO ".TBL_POKEMON." SET Trainer = :trainer, OTrainer = :otrainer, Pokemon = :pokemon, Shiny = $shiny, Level = 10, EXP = 1001, EXPN = 1331, HP = $hp2, MHP = $hp2, Gender = $pokemon_gender, Attack1 = $attack1, Attack2 = $attack2, Attack3 = $attack3, Attack4 = $attack4, Item = None"; 
      $stmt = $this->connection->prepare($query);
      return $stmt->execute(array(':trainer' => $username, ':otrainer' => $username, ':pokemon' => $starter));
   }

 

The only problem I'm having is the information is being stored into TBL_USERS but nothing is happeningto TBL_POKEMON. Can anyone point me in the right direction? I've tried changing the stmt variables too, but nothing. The information just won't get inserted into tbl_pokemon.

Link to comment
https://forums.phpfreaks.com/topic/260530-query-help/
Share on other sites

Yeah, I'm using PDO. Sorry about that... I found the error I'm guessing. $starter has no value, if I try to set it to other fields, I get the error

Integrity constraint violation: 1048

 

It also says I'm using a field which cannot be null. Could this be why the query won't get added?

Link to comment
https://forums.phpfreaks.com/topic/260530-query-help/#findComment-1335292
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.