2 Replies - 877 Views - Last Post: 09 December 2009 - 02:13 PM Rate Topic: -----

#1 nick1200   User is offline

  • Php Coder
  • member icon

Reputation: -19
  • View blog
  • Posts: 922
  • Joined: 21-March 09

Php and my sql not working the way it should

Post icon  Posted 09 December 2009 - 08:58 AM

i want the code to take the ehp down then the hp
the ehp is the computers hp and the hp is the hp of the person

i am trying to make the counter go up by 1 when the counter - 1
thats what the first bit is doing if the counter is over 1 then it will take 10 of hp
and put it back to 1 hope every 1 knows what im trying to do

<?php



$sql = "SELECT counter from battle WHERE username='".$_SESSION['username']."'";
$res = mysql_query($sql)  or die('Invalid query: ' . mysql_error());
$val = mysql_fetch_array($res);

echo $_SESSION['counter'];
echo $val['curhp'];
if (isset($_POST['submit'])) {
	if ($_SESSION['counter'] = 1) {
		$sql="UPDATE `battle` SET `ehp`=`ehp`-10 WHERE `username` = '" . $_SESSION['username'] . "'";
		$result=mysql_query($sql);
		echo "step 1";
	}else{
		$sql="UPDATE `battle` SET `hp`=`hp`-10 WHERE `username` = '" . $_SESSION['username'] . "'";
		$result=mysql_query($sql);
		echo "step 2";
	}
	$_SESSION['counter'] = 1;
}

$_SESSION['counter'] = 1;


?>



any idea's why its taking it off ehp but not hp

Is This A Good Question/Topic? 0
  • +

Replies To: Php and my sql not working the way it should

#2 relic5.2   User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 50
  • Joined: 26-November 08

Re: Php and my sql not working the way it should

Posted 09 December 2009 - 02:07 PM

if ($_SESSION['counter'] = 1) { will always return true.

Use if ($_SESSION['counter'] == 1) { instead
Was This Post Helpful? 0
  • +
  • -

#3 nick1200   User is offline

  • Php Coder
  • member icon

Reputation: -19
  • View blog
  • Posts: 922
  • Joined: 21-March 09

Re: Php and my sql not working the way it should

Posted 09 December 2009 - 02:13 PM

View Postrelic5.2, on 9 Dec, 2009 - 01:07 PM, said:

if ($_SESSION['counter'] = 1) { will always return true.

Use if ($_SESSION['counter'] == 1) { instead


still making ehp go down and not hp
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1