Jump to content

[SOLVED] Help me please


XxDeadmanxX

Recommended Posts

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";}
}

Link to comment
Share on other sites

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";
 }

?>

Link to comment
Share on other sites

<?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!";
}

?>
  



Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!";
}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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.

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.