I am having trouble with some PHP code working with HTML. I am making a simple program that just lets a user press a button to call a bunch of PHP practice code that I have made. Just basic PHP stuff.
I am new to PHP, and my HTML only returns the PHP in plain text.
My PHP code,
<body>
<?php
public function randomNumberComparsionAND() {
$_randomNum = rand(1, 100);
echo "The random number: " + $_randomNum + "\n";
if ($_randomNum % 4 == 0 && $_randomNum % 3 == 0) {
echo "The Number is evenly divisible by 3 and 4\n";
}
echo "The number is not evenly divisible by 3 and 4\n";
}
public function randomNumberComparsionOR() {
$_randomNum = rand(1, 100);
echo "The random number: " + $_randomNum + "\n";
if ($_randomNum % 4 == 0 || $_randomNum % 3 == 0) {
echo "The Number is evenly divisible by 3 or 4\n";
}
echo "The number is not evenly divisible by 3 or 4\n";
}
public function rollDice() {
$_dice1 = rand(1, 6);
$_dice2 = rand(1, 6);
if ($_dice1 == $_dice2) {
echo "The two dice are equal!\n";
}
echo "The two dice are not equal!\n";
}
randomNumberComparsionAND();
randomNumberComparsionOR();
rollDice();
?>
</body>
My HTML code,
<head>
<title>PHP Test</title>
<style>
body {
background-color: lightgrey;
}
</style>
</head>
<body>
<center>
<h1>Foo Test</h1>
<form action="php/index.php" method="get">
<label>Press Button to get PHP:</label><br><br>
<input type="submit" name="form">
</form>
</center>
<script>
</script>
</body>
Output:
The Error,
Expected results:
To execute the PHP code within the methods after clicking the submit button.
EDIT: Xampp is working fine now.