zerotolerance Posted April 8, 2012 Share Posted April 8, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/260530-query-help/ Share on other sites More sharing options...
creata.physics Posted April 8, 2012 Share Posted April 8, 2012 I'm going to assume you are using PDO even though you haven't said you are. If you are using PDO, click here to read on how to report your sql errors and you should be able to go that way. Quote Link to comment https://forums.phpfreaks.com/topic/260530-query-help/#findComment-1335290 Share on other sites More sharing options...
zerotolerance Posted April 8, 2012 Author Share Posted April 8, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/260530-query-help/#findComment-1335292 Share on other sites More sharing options...
zerotolerance Posted April 8, 2012 Author Share Posted April 8, 2012 Just fixed the $starter problem, I put the error display thing but no errors are displaying. If I remove the trainer query, the pokemon query seems to work just fine. Quote Link to comment https://forums.phpfreaks.com/topic/260530-query-help/#findComment-1335293 Share on other sites More sharing options...
zerotolerance Posted April 8, 2012 Author Share Posted April 8, 2012 Still trying, and confused :/. Quote Link to comment https://forums.phpfreaks.com/topic/260530-query-help/#findComment-1335327 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.