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