Jump to content

[SOLVED] What is wrong with my code?


Shiny_Charizard

Recommended Posts

<?PHP
session_start();
include('connect.php');
//Slot 1 Variables
$slot1_2= mysql_query("SELECT * FROM pokemon WHERE username='$_SESSION[username]' AND slot='1'");
$slot1= mysql_fetch_array($slot1_2);

if(isset($_POST['submit']))
{
$c_exp = $slot1['pkmn_exp2'];	
$a_exp = rand(10,20);
$exp = $c_exp + $a_exp;

$update_exp1 = "UPDATE pokemon SET pkmn_exp2='$exp' WHERE username='$_SESSION[username]' AND slot='1'";	
echo "Your $slot1[pkmn_name] gained <b>$exp</b> experience!";

//If pokemon gains level 
if($slot1['pkmn_exp2'] == $slot1['pkmn_exp'])
  {

$g_exp = rand(15,25);
$o_exp = $slot['pkmn_exp'];	  	  
$new_exp = $g_exp + $o_exp;

$g_level = 1;
$o_level = $slot1['pkmn_level'];
$n_level = $g_level + $o_level;

$updatelvl="UPDATE * pokemon SET pkmn_level='$n_level' WHERE slot='1' AND username='$_SESSION[username]'";
$update_exp="UPDATE * pokemon SET pkmn_exp='$new_exp' WHERE slot='1' AND username='$SESSION[username]'";

  echo"Your $slot1[pkmn_name] gained <b>1</b> level!";
}
	}
echo "<center>
<form action='gainexp.php' method='POST'>
Do you want your Pokémon to gain experience?
<br />
Click the button below to gain some.
<br />
<input type='submit' name='submit' value='Gain Exp'>
</br />
</form>
</center>";

?>

 

For some reason it doesn't update the MySQL rows. Can anybody please help me figure out what is wrong?

Link to comment
https://forums.phpfreaks.com/topic/86738-solved-what-is-wrong-with-my-code/
Share on other sites

Change this:

$updatelvl="UPDATE * pokemon SET pkmn_level='$n_level' WHERE slot='1' AND username='$_SESSION[username]'";
$update_exp="UPDATE * pokemon SET pkmn_exp='$new_exp' WHERE slot='1' AND username='$SESSION[username]'"

 

to this:

$updatelvl=mysql_query("UPDATE pokemon SET pkmn_level='$n_level' WHERE slot='1' AND username='$_SESSION[username]'");
$update_exp=mysql_query("UPDATE pokemon SET pkmn_exp='$new_exp' WHERE slot='1' AND username='$SESSION[username]'");

 

and let us know.

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.