Hi Guys. I'm still a php newbie. In our class, we have just discussed creating PHP functions. As expected, we were given some exercises. Unfortunately I was not able to make my self-made function. There were actually two files, namely; functions.php and max_of_3.php
the 'functions.php' is where the function is stored.
the max_of_3.php will be accessing the functions.php using 'include', however, like I said earlier, it won't work. Unfortunately I can't think of any other reasons why it doesn't work. Any suggestions?
Here is the code for the functions.php
<?php
//This function accepts three numbers and returns the biggest one.
function max_of_3($x,$y,$z)
{
if(($x > $y)and($x > $z))
{return $x;}
else if(($y > $x)and($y > $z))
{return $y;}
else
{return $z;}
}
?>
Now here's the code for the max_of_3.php
<html>
<head>
</head>
<title> Max of 3 </title>
<body>
<form name='Maxof3.php' method='post'>
<body bgcolor="white">
<font size="5" face="garamond" color="red">
<center>
<table border="20">
<tr>
<td bgcolor="black"><font color="white">Enter First Number</td></font>
<td bgcolor="black"><input type = "text" name = "First" size="20"></td>
</tr>
<tr>
<td bgcolor="black"><font color="white">Enter Second Number</td></font>
<td bgcolor="black"><input type = "text" name = "Second" size="20"></td>
</tr>
<tr>
<td bgcolor="black"><font color="white">Enter Third Number</td></font>
<td bgcolor="black"><input type = "text" name = "Third" size="20"></td>
</tr>
<tr>
<td></td>
<td><input type='submit' value='Submit'>
<input type='reset' value='Reset'>
</tr>
</table>
</form>
</body>
</html>
<?php
include ("functions.php");
$x = $_POST['First'];
$y = $_POST['Second'];
$z = $_POST['Third'];
$big = max_of_3($x,$y,$z);
echo "Biggest of the 3 is ";
echo $big;
?>
any help would be much appreciated! :)