XxDeadmanxX Posted October 4, 2007 Share Posted October 4, 2007 Ok im making a script it checks if its position 1 it makes it 2 . But this script isnt working ,can someone tell me wat i did wrong? $result = mysql_query("SELECT * FROM pokemons where username='$Valid_User'"); while($row = mysql_fetch_array($result)) if ($row['position']==""){ $positioncheck= 1; } else{ $positioncheck=($row['position']+1); if($positioncheck>6){$positioncheck="box";} } Quote Link to comment https://forums.phpfreaks.com/topic/71871-solved-help-me-please/ Share on other sites More sharing options...
darkfreaks Posted October 4, 2007 Share Posted October 4, 2007 <?php if ($row['position']==""){ $positioncheck=="1"; } else if{ $positioncheck=($row['position']+1);} else if($positioncheck>6){$positioncheck="box";} ?> Quote Link to comment https://forums.phpfreaks.com/topic/71871-solved-help-me-please/#findComment-362039 Share on other sites More sharing options...
trq Posted October 4, 2007 Share Posted October 4, 2007 Are you getting any errors? You really need to check your results before attempting to use them. <?php if ($result = mysql_query("SELECT * FROM pokemons where username='$Valid_User'")) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_array($result)) { if ($row['position']=="") { $positioncheck = 1; } else { $positioncheck = $row['position']+1; } } } else { echo "No results found"; } } else { die(mysql_error()); } if ($positioncheck > 6) { $positioncheck = "box"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/71871-solved-help-me-please/#findComment-362040 Share on other sites More sharing options...
XxDeadmanxX Posted October 4, 2007 Author Share Posted October 4, 2007 <?php if ($row['position']==""){ $positioncheck=="1"; } else if{ $positioncheck=($row['position']+1);} else if($positioncheck>6){$positioncheck="box";} ?> This gives me a error. And other guys still doesnt work . Heres the full code. <?php $pokemon= Bulbasaur; $Valid_User= $_SESSION['valid_user']; $result = mysql_query("SELECT * FROM dbUsers where username='$Valid_User'") or die(mysql_error()); $row = mysql_fetch_array($result); $username= $_POST['username']; if ($result = mysql_query("SELECT * FROM pokemons where username='$Valid_User'")) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_array($result)) { if ($row['position']=="") { $positioncheck = 1; } else { $positioncheck = $row['position']+1; } } } else { echo "No results found"; } } else { die(mysql_error()); } if ($positioncheck > 6) { $positioncheck = "box"; } if($row['promo']=="Yes") { echo "Sorry, $Valid_User you already have the pokemon."; exit; } if ($row['promo']=="No") { echo "Congrats, you got the promo."; mysql_query("INSERT INTO pokemons (username, pokemon, position) VALUES('$Valid_User', '$pokemon','$positioncheck')") or die(mysql_error()); mysql_query("UPDATE dbUsers SET promo='Yes' WHERE username='$Valid_User'"); } else { echo "ERROR!"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/71871-solved-help-me-please/#findComment-362042 Share on other sites More sharing options...
trq Posted October 4, 2007 Share Posted October 4, 2007 Sorry, your code is all over the place. For starters, do you expect more than one row from your SELECT query? If not, we can get rid of the while loop. Also, define not working. Are you getting any error? ps: I see no call to session_start() yet you are accessing the $_SESSION array. Quote Link to comment https://forums.phpfreaks.com/topic/71871-solved-help-me-please/#findComment-362044 Share on other sites More sharing options...
desithugg Posted October 4, 2007 Share Posted October 4, 2007 The variable $Valid_User isn't being defined properly anywhere. Trying using echo to make sure the $Valid_User variable is set. So try putting echo $Valid_User; at the top to make sure it's being set. Quote Link to comment https://forums.phpfreaks.com/topic/71871-solved-help-me-please/#findComment-362045 Share on other sites More sharing options...
XxDeadmanxX Posted October 4, 2007 Author Share Posted October 4, 2007 Sorry, your code is all over the place. For starters, do you expect more than one row from your SELECT query? If not, we can get rid of the while loop. Also, define not working. Are you getting any error? ps: I see no call to session_start() yet you are accessing the $_SESSION array. i have the session start on the main page. I include the page from the index page. And the error im geting is the one at bottom. } else { echo "ERROR!"; } Quote Link to comment https://forums.phpfreaks.com/topic/71871-solved-help-me-please/#findComment-362046 Share on other sites More sharing options...
trq Posted October 4, 2007 Share Posted October 4, 2007 Firstly, are you expecting more than one row from your query? We really need to fix a bunch of logic because you are using $row outside of your loop, this will cause all sorts of issues. Quote Link to comment https://forums.phpfreaks.com/topic/71871-solved-help-me-please/#findComment-362048 Share on other sites More sharing options...
desithugg Posted October 4, 2007 Share Posted October 4, 2007 Here I rewrote the whole thing for you. Give it a try. <?php $pokemon= Bulbasaur; $Valid_User= $_SESSION['valid_user']; $result = mysql_query("SELECT * FROM dbUsers where username='".$Valid_User."'") or die(mysql_error()); $row = mysql_fetch_array( $result ); $promo_row = $row['promo']; $result = mysql_query("SELECT * FROM pokemons where username='".$Valid_User."' order by position desc limit 1") or die(mysql_error()); $row = mysql_fetch_array( $result ); $positioncheck = $row['position']; if(!isset($positioncheck) OR $positioncheck=="" OR $positioncheck=="0"){ $positioncheck=1; }else{ $positioncheck = ($positioncheck+1); } if($positioncheck>6){ $positioncheck="box"; } if($promo_row!="No"){ echo "Sorry, ".$Valid_User." you already have the pokemon."; exit; }else{ echo "Congrats, you got the promo."; mysql_query("INSERT INTO pokemons (username, pokemon, position) VALUES('".$Valid_User."', '".$pokemon."','".$positioncheck."')")or die(mysql_error()); mysql_query("UPDATE dbUsers SET promo='Yes' WHERE username='".$Valid_User."'"); } ?> Next time use it as a reference when fetching information from the database. Quote Link to comment https://forums.phpfreaks.com/topic/71871-solved-help-me-please/#findComment-362051 Share on other sites More sharing options...
trq Posted October 4, 2007 Share Posted October 4, 2007 Next time use it as a reference when fetching information from the database. Without trying to be nasty, that is some seriously poor reference material. Quote Link to comment https://forums.phpfreaks.com/topic/71871-solved-help-me-please/#findComment-362053 Share on other sites More sharing options...
desithugg Posted October 4, 2007 Share Posted October 4, 2007 Next time use it as a reference when fetching information from the database. Without trying to be nasty, that is some seriously poor reference material. I'm aware, I didn't add any comments and stuff. But I have other things to do. I'm pretty sure he can make out how to fetch single rows form the database now. Quote Link to comment https://forums.phpfreaks.com/topic/71871-solved-help-me-please/#findComment-362055 Share on other sites More sharing options...
XxDeadmanxX Posted October 4, 2007 Author Share Posted October 4, 2007 Here I rewrote the whole thing for you. Give it a try. <?php $pokemon= Bulbasaur; $Valid_User= $_SESSION['valid_user']; $result = mysql_query("SELECT * FROM dbUsers where username='".$Valid_User."'") or die(mysql_error()); $row = mysql_fetch_array( $result ); $promo_row = $row['promo']; $result = mysql_query("SELECT * FROM pokemons where username='".$Valid_User."' order by position desc limit 1") or die(mysql_error()); $row = mysql_fetch_array( $result ); $positioncheck = $row['position']; if(!isset($positioncheck) OR $positioncheck=="" OR $positioncheck=="0"){ $positioncheck=1; }else{ $positioncheck = ($positioncheck+1); } if($positioncheck>6){ $positioncheck="box"; } if($promo_row!="No"){ echo "Sorry, ".$Valid_User." you already have the pokemon."; exit; }else{ echo "Congrats, you got the promo."; mysql_query("INSERT INTO pokemons (username, pokemon, position) VALUES('".$Valid_User."', '".$pokemon."','".$positioncheck."')")or die(mysql_error()); mysql_query("UPDATE dbUsers SET promo='Yes' WHERE username='".$Valid_User."'"); } ?> Next time use it as a reference when fetching information from the database. TY man that works.Respect +++ lol. Quote Link to comment https://forums.phpfreaks.com/topic/71871-solved-help-me-please/#findComment-362056 Share on other sites More sharing options...
trq Posted October 4, 2007 Share Posted October 4, 2007 I'm aware, I didn't add any comments and stuff. But I have other things to do. I'm pretty sure he can make out how to fetch single rows form the database now. Its not the lack of coments thats the problem. There is absolutley no error handling, which IMO is always poor code. Even if it works now, it may not always work. Quote Link to comment https://forums.phpfreaks.com/topic/71871-solved-help-me-please/#findComment-362057 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.