We’re going to create a class that will have our methods.

File Letter.class.php – the name has to be with capital letter and the .class.php

<?
//create the class that has to be in capital letter ’cause it’s the name of the class
Class Letter{
//stating the variables
public $a;
public $b;
//creating the constructor method and starting the variables
function __construct($a,$b){
$this->a = $a;
$this->b = $b;
}
//creating a function that will check the variables
public function checking(){
if ($this->a==$this->b){
echo “A is equal B”;
}
else {
echo “A isn’t equal B”;
}
}
}
?>

 

File checking.php – this file will inclue the class to create the object and the form.

<?php
/ / Including class Letter
include_once (“Letter.class.php”);
/ / Getting the GET variable form
$action = $_GET[‘action’];
if ($action == ‘check’) (
/ / Getting values form
$a = $_POST[‘A’];
$b = $_POST[‘B’];
/ / Creating and instantiating the object and letter assigning values to this object
$letter = new Letter ($a, $b);
/ / Calling function check
$letter->checkbox();
)
?>
<form name=”checking” method=”post” action=”?action=check”>
<p>
<label for=”a”> A: </ label>
<input name=”A” type=”text” id=”a” />
<label for=”b”> B: </ label>
<input name=”B” type=”text” id=”b” />
<input type=”submit” name=”submit” value=”Submit”>
</ Form>