Źle zrozumiany operator AND?

0

Cześć jestem kompletnie początkującym, kiedyś tam troche w html działałem, więc postawniłem rozszerzyć wiedzę jakimś językiem, padło na php.
Kod na początku był dużo prostszy, ale dodawałem nawiasy, zmieniałem nazwy zmiennych, użyłem 'AND' zamiast '&&' itd. w poszukiwaniu błędu, lecz dalej nie wiem o co chodzi, podaję więc kod:

<html>
<head><title></title><head>
<body>

	<form action="beta1.php" method="post">
		Enter number 3 numbers: </br> </br>
		<input type="number" name="num1">
		</br>
		<input type="number" name="num2">
		</br>
		<input type="number" name="num3">
		</br>
		<input type="submit" text="let's do this">
	</form>
	</br> 
	
	<?php 
	$num1 = $_POST["num1"];
	$num2 = $_POST["num2"];
	$num1 = $_POST["num3"];
	function whatMax($numb1, $numb2, $numb3) {
		if(($numb1 >= $numb2) AND ($numb1 >= $numb3)) {
			return $numb1;
		}
		elseif(($numb2 >= $numb1) AND ($numb2 >= $numb3)) {
			return $numb2;
		}
		elseif (($numb3 >= $numb1) AND ($numb3 >= $numb2)){
			return $numb3;
		
		}
		
	}
	
	$result = whatMax($num1, $num2, $num3);
	
	echo "$result is the biggest ";
	
	?>



</body>

</html>

I zwraca mi to, kiedy 3 liczba jest większa od 2, a i tak 1 pierwsza w rzeczywistości jest największa - tak czy siak zwraca 3.
screenshot-20190810172414.png
Błąd pewnie banalny, ale już kupe czasu straciłem a nie pójdę dalej jeśli się nie dowiem o co chodzi.
Pozdrawiam.

1

linijka nr 20

$num1 = $_POST["num3"];

Przeglądarka ci nie wyświetla czegoś w tym rodzaju przypadkiem?
Notice: Undefined variable: num3 in index.php on line 35

0
sugar_hiccup napisał(a):

linijka nr 20

$num1 = $_POST["num3"];

Przeglądarka ci nie wyświetla czegoś takiego przypadkiem?
Notice: Undefined variable: num3 in ~/dev/playground/test/index.php on line 35
Właśnie nie wyświetla, dzięki :D, bo już zgłupiałem.

0

Ogarniasz 3 liczby, a w kodzie taki kwiatek

    $num1 = $_POST["num1"];
    $num2 = $_POST["num2"];
    $num1 = $_POST["num3"]; //<--------------- chyba $num3 powinienes miec
0

Nie będę tworzył nowego tematu, może ktoś tu zajrzy i pomoże :D


<?php
// jestem głupi, teraz statystki na pewno zrobie w tablicy z key values, ale jak tak zacząłem to tak skończe :D


class Unit {
	
	public $name;
	public $hp;
	public $armor1;
	public $armor2;
	public $dmg1;
	public $dmg2;
	public $stat1;
	public $stat2;
	public $stat3;
	
	public function __construct($name, $hp, $armor1, $armor2, $dmg1, $dmg2, $stat1, $stat2, $stat3){
		$this->name = $name;
		$this->hp = $hp;
		$this->armor1 = $armor1;
		$this->armor2 = $armor2;
		$this->dmg1 = $dmg1;
		$this->stat1 = $stat1;
		$this->stat2 = $stat2;
		$this->stat3 = $stat3;
	}
}

class myHero extends Unit {
	
	public $avaiblePoints = 1; //przykładowo
	
	public function __construct($name, $hp, $armor1, $armor2, $dmg1, $dmg2, $stat1, $stat2, $stat3, $avaiblePoints){
		parent::__construct($name, $hp, $armor1, $armor2, $dmg1, $dmg2, $stat1, $stat2, $stat3);
		$this->avaiblePoints = $avaiblePoints;
		
	function addStat($stat_name){ //dobrze to?
		if($this->avaiblePoints >= 1){
			$stat_name++;
			$this->avaiblePoints--;
			
		}
	}
	
	
	}
}

$Hero = new myHero("xd", 100, 90, 40, 50, 60,  50, 20, 25, 1);

//przywołam teraz bohatera, moge później, ale wole mieć pewność że attackIt() niżej zadziała


class Monster extends Unit {
	
	public $rewardPoints = 0; //nie wiem czy to musze już przydzielać
	
	public function __construct($name, $hp, $armor1, $armor2, $dmg1, $dmg2, $stat1, $stat2, $stat3){ //później sobie te statystki odpuszcze u monsters
		parent::__construct($name, $hp, $armor1, $armor2, $dmg1, $dmg2, $stat1, $stat2, $stat3);
		
}

	function attackIt(){
		$i = 1;
		$revertHP = $Hero->hp;
		while($i > 0) { //nie wiem czy tak sie robi :D
			$dmgDone = rand($Hero->dmg1, $Hero-dmg2); 
			$dmgReceived = rand($this->dmg1, $this->dmg2);
			$this->hp =- $dmgDone;
			echo "Zadałeś" . $dmgDone . "obrażeń";
			$Hero->hp =- $dmgReceived;
			echo "Otrzymałeś" . $dmgReceived . "obrażeń";
			if ($this->hp < 0){
				echo "Wygrałeś!";
				$Hero->avaiblePoints = $this->rewardPoints;
				$Hero->hp = $revertHP;
				break;
				}
			elseif ($Hero->hp < 0) {
				echo "Przegrałeś!";
				$Hero->hp = $revertHP;
				break;
			}
				
			}
			
		}
	}


//Hero->addStat()
echo $Hero->name;
$Hero->addStat($Hero->stat1);
echo $Hero->stat1;

?>

Chodzi konkretnie o te fragmenty:


class myHero extends Unit {
	
	public $avaiblePoints = 1; //przykładowo
	
	public function __construct($name, $hp, $armor1, $armor2, $dmg1, $dmg2, $stat1, $stat2, $stat3, $avaiblePoints){
		parent::__construct($name, $hp, $armor1, $armor2, $dmg1, $dmg2, $stat1, $stat2, $stat3);
		$this->avaiblePoints = $avaiblePoints;
[....]
	function addStat($stat_name){ //dobrze to?
		if($this->avaiblePoints >= 1){
			$stat_name++;
			$this->avaiblePoints--;

[...]

$Hero->addStat($Hero->stat1);


1 użytkowników online, w tym zalogowanych: 0, gości: 1