When my code is moved from local server to live server it shows an error like this :
Fatal error: Call to undefined method DateTime::diff()
Code:
<?php
date_default_timezone_set('Asia/Calcutta');
$sFinalDate = date('Y-m-d', strtotime($sDate));
$sNow = new DateTime();
$iRemain = new DateTime( $sFinalDate.$sTime);
$iInterval = $iRemain->diff($sNow);
$sTimeCounter = $iInterval->format("%h: %i :%s ");
$sCalculate = $iInterval->format("%a:%h:%i");
?>
Though I found a number of people who ran into the issue of 5.2 and
lower not supporting this function, I was unable to find any solid
examples to get around it. Therefore I hope this can help some others:
<?php
function get_timespan_string($older, $newer) {
$Y1 = $older->format('Y');
$Y2 = $newer->format('Y');
$Y = $Y2 - $Y1;
$m1 = $older->format('m');
$m2 = $newer->format('m');
$m = $m2 - $m1;
$d1 = $older->format('d');
$d2 = $newer->format('d');
$d = $d2 - $d1;
$H1 = $older->format('H');
$H2 = $newer->format('H');
$H = $H2 - $H1;
$i1 = $older->format('i');
$i2 = $newer->format('i');
$i = $i2 - $i1;
$s1 = $older->format('s');
$s2 = $newer->format('s');
$s = $s2 - $s1;
if($s < 0) {
$i = $i -1;
$s = $s + 60;
}
if($i < 0) {
$H = $H - 1;
$i = $i + 60;
}
if($H < 0) {
$d = $d - 1;
$H = $H + 24;
}
if($d < 0) {
$m = $m - 1;
$d = $d + get_days_for_previous_month($m2, $Y2);
}
if($m < 0) {
$Y = $Y - 1;
$m = $m + 12;
}
$timespan_string = create_timespan_string($Y, $m, $d, $H, $i, $s);
return $timespan_string;
}
function get_days_for_previous_month($current_month, $current_year) {
$previous_month = $current_month - 1;
if($current_month == 1) {
$current_year = $current_year - 1; //going from January to previous December
$previous_month = 12;
}
if($previous_month == 11 || $previous_month == 9 || $previous_month == 6 || $previous_month == 4) {
return 30;
}
else if($previous_month == 2) {
if(($current_year % 4) == 0) { //remainder 0 for leap years
return 29;
}
else {
return 28;
}
}
else {
return 31;
}
}
function create_timespan_string($Y, $m, $d, $H, $i, $s)
{
$timespan_string = '';
$found_first_diff = false;
if($Y >= 1) {
$found_first_diff = true;
$timespan_string .= pluralize($Y, 'year').' ';
}
if($m >= 1 || $found_first_diff) {
$found_first_diff = true;
$timespan_string .= pluralize($m, 'month').' ';
}
if($d >= 1 || $found_first_diff) {
$found_first_diff = true;
$timespan_string .= pluralize($d, 'day').' ';
}
if($H >= 1 || $found_first_diff) {
$found_first_diff = true;
$timespan_string .= pluralize($H, 'hour').' ';
}
if($i >= 1 || $found_first_diff) {
$found_first_diff = true;
$timespan_string .= pluralize($i, 'minute').' ';
}
if($found_first_diff) {
$timespan_string .= 'and ';
}
$timespan_string .= pluralize($s, 'second');
return $timespan_string;
}
function pluralize( $count, $text )
{
return $count . ( ( $count == 1 ) ? ( " $text" ) : ( " ${text}s" ) );
}
?>
source http://php.net/manual/en/function.date-diff.php
if you using php 5.3 then there would be another issue
working above example on php>=5.3
i want to add all digit in a number and if it is 11,22 then i want to display only 11 or 22 else i want to make it a single digit.
example 30=3+0=3
28=2+8=10=1+0=1
i just made a codebut it have an error
please help.
<?php
$day = 17;
$month = 8;
$year = 1993;
function sumday($day)
{
if ($day == 11)
{
$sday = 11;
}
elseif ($day == 22)
{
$sday = 22;
}
elseif ($day == 29)
{
$sday = 11;
}
else
{
do {
$nday = $day . "";
$sday = 0;
for ($i = 0; $i < strlen($nday); ++$i)
{
$sday += $nday[$i];
}
while ($sday <=9);
}
return $sday;
}
First of all I would suggest you to learn to separate the tasks that a function do.
You ask to sum up the digits of a number, you may first create a function called sum_digits
<?php
function sum_digits($num) {
if ($num < 10)
return $num;
return $num % 10 + sum_digits(floor($num/10));
}
and then via conditional do whatever you need to do.
please refer to unnikked's answer, that's a good answer.
And here's the full code, combined with unnikked's answer
<?php
$day = 17;
$month = 8;
$year = 1993;
function sumday($day)
{
if ($day == 11)
{
$sday = 11;
}
elseif ($day == 22)
{
$sday = 22;
}
elseif ($day == 29)
{
$sday = 11;
}
else{
$sday = $day;
do {
$sday = $sday % 10 + floor($sday/10);
} while ($sday >= 10);
}
return $sday;
}
?>
EDIT: If you want to return the sum if it's 11,22,33 in the while loop, then put the conditions in the while loop rather than using if else condition, it's much simpler tho :)
function sumday($day)
{
$sday = $day;
while ($sday >= 10 && $sday != 11 && $sday != 22 && $sday != 29){
$sday = $sday % 10 + floor($sday/10);
}
return $sday;
}
EDIT: here's the logic that can split the day and sum them
function sumday($day)
{
$sday = $day;
$arrday = str_split($sday); // split the day into array
$sumarrday = 0;
for($i = 0; $i < strlen((string)$sday); $i++){
$sumarrday = $sumarrday + $arrday[$i]; // sum the day from the array
}
$sday = $sumarrday;
// here you can modify the condition of while statement for your needs
// for example, if you want to return 29 when 29 shows up, add this to your condition, && $sday != 29
while ($sday >= 10){
$sday = $sday % 10 + floor($sday/10);
}
return $sday;
}
Try this:
else {
$nday = $day . ""; //moved out wrom loop
do {
$sday = 0;
for ($i = 0; $i < strlen($nday); ++$i)
{
$sday += $nday[$i];
}
$nday = $sday . ""; // you forget this line
while ($sday <=9);
}
I have multiple JavaScript functions to calculate mayan horoscope sign, which I converted to a single PHP class. Everything works well, except some dates. For example, the date 06.10.1977 gives me a NULL result using the PHP class, but this date in the equivalent JavaScript function returns a proper value. Maybe I've got something wrong in PHP so, can somebody check this up for me?
JAVASCRIPT:
function leap_gregorian(year) {
return ((year % 4) == 0) && (!(((year % 100) == 0) && ((year % 400) != 0)));
}
// GREGORIAN_TO_JD -- Determine Julian day number from Gregorian calendar date
var GREGORIAN_EPOCH = 1721425.5;
function gregorian_to_jd(year, month, day) {
return (GREGORIAN_EPOCH - 1) +
(365 * (year - 1)) +
Math.floor((year - 1) / 4) +
(-Math.floor((year - 1) / 100)) +
Math.floor((year - 1) / 400) +
Math.floor((((367 * month) - 362) / 12) +
((month <= 2) ? 0 : (leap_gregorian(year) ? -1 : -2)) +
day);
}
var MAYAN_COUNT_EPOCH = 584282.5;
// JD_TO_MAYAN_COUNT -- Calculate Mayan long count from Julian day
function jd_to_mayan_count(jd) {
var d, baktun, katun, tun, uinal, kin;
jd = Math.floor(jd) + 0.5;
d = jd - MAYAN_COUNT_EPOCH;
baktun = Math.floor(d / 144000);
d = mod(d, 144000);
katun = Math.floor(d / 7200);
d = mod(d, 7200);
tun = Math.floor(d / 360);
d = mod(d, 360);
uinal = Math.floor(d / 20);
kin = mod(d, 20);
return new Array(baktun, katun, tun, uinal, kin);
}
// JD_TO_MAYAN_HAAB -- Determine Mayan Haab "month" and day from Julian day
var MAYAN_HAAB_MONTHS = new Array("Pop", "Uo", "Zip", "Zotz", "Tzec", "Xul",
"Yaxkin", "Mol", "Chen", "Yax", "Zac", "Ceh",
"Mac", "Kankin", "Muan", "Pax", "Kayab", "Cumku", "Uayeb");
function jd_to_mayan_haab(jd) {
var lcount, day;
jd = Math.floor(jd) + 0.5;
lcount = jd - MAYAN_COUNT_EPOCH;
day = mod(lcount + 8 + ((18 - 1) * 20), 365);
return new Array(Math.floor(day / 20) + 1, mod(day, 20));
}
// JD_TO_MAYAN_TZOLKIN -- Determine Mayan Tzolkin "month" and day from Julian day
var MAYAN_TZOLKIN_MONTHS = new Array("Imix", "Ik", "Akbal", "Kan", "Chicchan",
"Cimi", "Manik", "Lamat", "Muluc", "Oc",
"Chuen", "Eb", "Ben", "Ix", "Men",
"Cib", "Caban", "Etznab", "Cauac", "Ahau");
var MAYAN_TZOLKIN_MONTHS_EN = new Array("Crocodile", "Wind", "House", "Lizard", "Serpent",
"Death", "Deer", "Rabbit", "Water", "Dog",
"Monkey", "Grass", "Reed", "Jaguar", "Eagle",
"Vulture", "Earth", "Knife", "Storm", "Flower");
function jd_to_mayan_tzolkin(jd) {
var lcount;
jd = Math.floor(jd) + 0.5;
lcount = jd - MAYAN_COUNT_EPOCH;
return new Array(amod(lcount + 20, 20), amod(lcount + 4, 13));
}
function getMayanSign(sign, month, day, year) {
var isValidated = true;
var result = "";
if (!IsNumeric(month.value) || month.value <= 0 || month.value > 12) {
month.value = "MM";
isValidated = false;
}
if (!IsNumeric(day.value) || day.value <= 0 || day.value > 31) {
day.value = "DD";
isValidated = false;
}
if (!IsNumeric(year.value) || year.value < 1900 ) {
year.value = "YYYY";
isValidated = false;
}
if (isValidated) {
year = new Number(year.value);
mon = new Number(month.value);
mday = new Number(day.value);
hour = min = sec = 0;
// Update Julian day
j = gregorian_to_jd(year, mon + 0, mday) +
(Math.floor(sec + 60 * (min + 60 * hour) + 0.5) / 86400.0);
maytzolkincal = jd_to_mayan_tzolkin(j);
result = MAYAN_TZOLKIN_MONTHS_EN[maytzolkincal[0] - 1];
} else result = "INVALID BIRTHDAY";
sign.value = result;
}
PHP CLASS:
class MayanCalculator {
// JD_TO_MAYAN_TZOLKIN -- Determine Mayan Tzolkin "month" and day from Julian day
private $MAYAN_TZOLKIN_MONTHS = array("Imix", "Ik", "Akbal", "Kan", "Chicchan",
"Cimi", "Manik", "Lamat", "Muluc", "Oc",
"Chuen", "Eb", "Ben", "Ix", "Men",
"Cib", "Caban", "Etznab", "Cauac", "Ahau");
private $MAYAN_TZOLKIN_MONTHS_EN = array("Crocodile", "Wind", "House", "Lizard", "Serpent",
"Death", "Deer", "Rabbit", "Water", "Dog",
"Monkey", "Grass", "Reed", "Jaguar", "Eagle",
"Vulture", "Earth", "Knife", "Storm", "Flower");
private $GREGORIAN_EPOCH = 1721425.5;
private $MAYAN_COUNT_EPOCH = 584282.5;
private $MAYAN_HAAB_MONTHS = array("Pop", "Uo", "Zip", "Zotz", "Tzec", "Xul",
"Yaxkin", "Mol", "Chen", "Yax", "Zac", "Ceh",
"Mac", "Kankin", "Muan", "Pax", "Kayab", "Cumku", "Uayeb");
private $_day;
private $_month;
private $_year;
private $sign;
private $signm;
function __construct($day, $month, $year) {
$this->_day = $day;
$this->_month = $month;
$this->_year = $year;
}
public function getMayanSign() {
$this->sign = $this->getSign();
$this->signm = $this->getMayanSignOnMayan();
$ids = new getIDS(null,null,$this->sign);
$id = $ids->returnIDS();
return array("mayan_sign" => $this->sign, "mayan_sign_on_mayan" => $this->signm, "mayan_sign_id" => $id["mayan_id"]);
}
private function getSign() {
$isValidated = true;
$result = null;
if (!is_numeric($this->_month) || $this->_month <= 0 || $this->_month > 12) :
$isValidated = false;
endif;
if (!is_numeric($this->_day) || $this->_day <= 0 || $this->_day > 31) :
$isValidated = false;
endif;
if (!is_numeric($this->_year) || $this->_year < 1900) :
$isValidated = false;
endif;
if ($isValidated) :
$hour = 0;
$min = 0;
$sec = 0;
//update julian day
$j = $this->gregorian_to_jd($this->_year, $this->_month+0, $this->_day) + (floor($sec + 60 * ($min + 60 * $hour) + 0.5) / 86400.0);
$maytzolkincal = $this->jd_to_mayan_tzolkin($j);
$result = $this->MAYAN_TZOLKIN_MONTHS_EN[$maytzolkincal[0]-1];
else :
$result = 'Wrong date '. $this->_day . '.' . $this->_month . '.' . $this->_year;
endif;
return $result;
}
private function getMayanSignOnMayan() {
$isValidated = true;
$result = null;
if (!is_numeric($this->_month) || $this->_month <= 0 || $this->_month > 12) :
$isValidated = false;
endif;
if (!is_numeric($this->_day) || $this->_day <= 0 || $this->_day > 31) :
$isValidated = false;
endif;
if (!is_numeric($this->_year) || $this->_year < 1900) :
$isValidated = false;
endif;
if ($isValidated) :
$hour = 0;
$min = 0;
$sec = 0;
//update julian day
$j = $this->gregorian_to_jd($this->_year, $this->_month+0, $this->_day) + (floor($sec + 60 * ($min + 60 * $hour) + 0.5) / 86400);
$maytzolkincal = $this->jd_to_mayan_tzolkin($j);
$result = $this->MAYAN_TZOLKIN_MONTHS[$maytzolkincal[0]]-1;
else :
$result = 'Wrong date '. $this->_day . '.' . $this->_month . '.' . $this->_year;
endif;
return $result;
}
private function leap_gregorian($year) {
return (($year % 4) == 0) && (!((($year % 100) == 0) && (($year % 400) != 0)));
}
private function gregorian_to_jd($year, $month, $day) {
$result = ($this->GREGORIAN_EPOCH - 1) +
(365 * ($year - 1)) +
floor(($year - 1) / 4) +
(-floor(($year - 1) / 100)) +
floor(($year - 1) / 400) +
floor((((367 * $month) - 362) / 12) +
(($month <= 2) ? 0 : ($this->leap_gregorian($year) ? -1 : -2)) +
$day);
return $result;
}
private function jd_to_mayan_count($jd) {
$jd = floor($jd) + 0.5;
$d = $jd - $this->MAYAN_COUNT_EPOCH;
$baktun = floor($d / 144000);
$d = $d % 144000;
$katun = floor($d / 7200);
$d = $d % 7200;
$tun = floor($d / 360);
$d = $d % 360;
$uinal = floor($d / 20);
$kin = $d % 20;
return array($baktun, $katun, $tun, $uinal, $kin);
}
private function jd_to_mayan_haab($jd) {
$jd = floor($jd) + 0.5;
$lcount = $jd - $this->MAYAN_COUNT_EPOCH;
$day = ($lcount + 8 + ((18 - 1) * 20)) % 365;
return array(floor($day / 20) + 1, $day % 20);
}
private function jd_to_mayan_tzolkin($jd) {
$jd = floor($jd) + 0.5;
$lcount = $jd - $this->MAYAN_COUNT_EPOCH;
return array(($lcount + 20) % 20, ($lcount + 4) % 13);
}
}
First: Always post all relevant script. Yours was missing the JavaScript function amod() which is crucial to solving your problem, I found it in the original here
Your PHP function jd_to_mayan_tzolkin() ist different from your JavaScript function jd_to_mayan_tzolkin():
While JavaScript uses a separate function amod() to calculate the modulus and returns the numerator if the modulus-result is 0
// AMOD -- Modulus function which returns numerator if modulus is zero
function amod($a, $b) {
return $this->mod($a - 1, $b) + 1;
}
your php function just returns the modulus which can be 0 and therefore the further processing of your PHP fails.
Add the following two functions to your class:
/* MOD -- Modulus function which works for non-integers. */
private function mod($a, $b) {
return $a - ($b * floor($a / $b));
}
// AMOD -- Modulus function which returns numerator if modulus is zero
private function amod($a, $b) {
return $this->mod($a - 1, $b) + 1;
}
And change the PHP method jd_to_mayan_tzolkin() as follows:
private function jd_to_mayan_tzolkin($jd) {
$jd = floor($jd) + 0.5;
$lcount = $jd - $this->MAYAN_COUNT_EPOCH;
return array($this->amod(($lcount + 20),20), $this->amod(($lcount + 4),13));
}
I have a script which calls this function more than 100k times, so I am looking for anyway to squeeze a bit more performance out of it.
Can you suggest optimisations or an alternate method for calculating standard deviation in PHP?
function calcStandardDev($samples){
$sample_count = count($samples);
for ($current_sample = 0; $sample_count > $current_sample; ++$current_sample) $sample_square[$current_sample] = pow($samples[$current_sample], 2);
return sqrt(array_sum($sample_square) / $sample_count - pow((array_sum($samples) / $sample_count), 2));
}
$samples[$current_sample] * $samples[$current_sample]
is going to be faster than
pow($samples[$current_sample], 2)
because it doesn't have the overhead of the function call.
Then you can also simplify
pow((array_sum($samples) / $sample_count), 2));
to prevent calling the pow() function again
To avoid array_sum($samples) being called twice as a result of that change, calculate it once and store to a var before the loop, then just reference that var in the formula.
EDIT
function calcStandardDev($samples){
$sample_count = count($samples);
$sumSamples = array_sum($samples);
for ($current_sample = 0; $sample_count > $current_sample; ++$current_sample)
$sample_square[$current_sample] = $samples[$current_sample] * $samples[$current_sample];
return sqrt(array_sum($sample_square) / $sample_count - ( ($sumSamples / $sample_count) *
($sumSamples / $sample_count)
)
);
}
foreach by referance is faster than for, an you already have a loop, you can calculate "sum" in this loop. and $x*$x is so faster then pow($x,2);
there are some functions comparations. hope to help.
Your Function microtime = ~ 0.526
Second Function = ~ 0.290
<?php
function calcStandardDev($samples)
{
$sample_count = count($samples);
for ($current_sample = 0; $sample_count > $current_sample; ++$current_sample)
$sample_square[$current_sample] = pow($samples[$current_sample], 2);
return sqrt(array_sum($sample_square) / $sample_count - pow((array_sum($samples) / $sample_count), 2));
}
function calcStandardDev2($samples)
{
$sample_count = count($samples);
$sum_sample_square = 0;
$sum_sample = 0;
foreach ($samples as &$sample)
{
$sum_sample += $sample;
$sum_sample_square += $sample * $sample;
}
return sqrt($sum_sample_square / $sample_count - pow($sum_sample / $sample_count,2));
}
function calcStandardDev3($samples)
{
$sample_count = count($samples);
$sum_sample_square = 0;
$sum_sample = 0;
foreach ($samples as &$sample)
{
$sum_sample += $sample;
$sum_sample_square += pow($sample ,2);
}
return sqrt($sum_sample_square / $sample_count - pow($sum_sample / $sample_count,2));
}
echo "<pre>";
$samples = range(2,100000);
$start = microtime(true);
echo calcStandardDev($samples)."\r\n";
$end = microtime(true);
echo $end - $start ."\r\n";
echo "-------\r\n";
$start = microtime(true);
echo calcStandardDev2($samples)."\r\n";
$end = microtime(true);
echo $end - $start."\r\n";
echo "-------\r\n";
$start = microtime(true);
echo calcStandardDev3($samples)."\r\n";
$end = microtime(true);
echo $end - $start;
echo "-------\r\n";
?>
Replace both call to array_sum by calculating the respective values yourself. That way you just walk through your array one time instead of three times.
function calcStandardDev($samples){
$sample_count = count($samples);
$sum = 0;
$sum_sqaure = 0;
for ($current_sample = 0; $sample_count > $current_sample; ++$current_sample) {
$sum_square += pow($samples[$current_sample], 2);
$sum += $samples[$current_sample];
}
return sqrt( $sum_square / $sample_count - pow( $sum / $sample_count, 2));
}
How do I get this PHP code to output HTML in order to enter the player's number and generate the tournament?
<?php
class RoundRobin
{
var $MaxTeams;
var $MaxCombinations;
var $tourn;
var $mList;
var $cList;
var $cUsed;
function RoundRobin($max)
{
$this->MaxTeams=$max;
$this->MaxCombinations=($this->MaxTeams/2)*($this->MaxTeams-1);
}
function ShowSchedule($players,$totalChecks)
{
echo $players.' players'."\n";
for ($r=1; $r <= $players/2; $r++) echo 'Game'.$r;
echo "\n";
echo" +-";
for ($r=1; $r <= ($players/2)*6-2; $r++) echo '-';
echo "\n";
$index = 1;
for ($r=1; $r <= $players-1; $r++)
{
echo 'Week '.$r. '|';
for ($m=1; $m <= $players/2; $m++)
{
echo $this->tourn[$index]['one'].'&'. $this->tourn[$index]['two'];
$index++;
}
echo "\n";
}
echo "\n".$totalChecks,' combinations tried'. "\n\n";
}
function array_copy(&$dest,$source)
{
if(count($source)>count($dest)) {echo 'fatal'; exit;}
//for($a=0;$a<count($source);$a++)
$dest['one']=$source['one'];
$dest['two']=$source['two'];
}
function ClearArrays()
{
for ($i=0; $i <= $this->MaxCombinations; $i++)
{
$this->tourn[$i]['one']=0;
$this->tourn[$i]['two']=0;
$this->cList[$i]['one']=0;
$this->cList[$i]['two']=0;
$this->cUsed[$i]=0;
if($i<=$this->MaxTeams/2)$this->mList[$i] = 0;
}
}
function Scheldule($players)
{
while ($players <= $this->MaxTeams)
{
$combinations = $players/2 * ($players-1);
$totalChecks = 0;
$this->ClearArrays();
/* set up list of all combinations */
$m=1;
for ($a=1; $a<$players; $a++)
for ($b=$a+1; $b<=$players; $b++)
{
$this->cList[$m]['one'] = $a;
$this->cList[$m]['two'] = $b;
$m++;
}
$roundCount=1;
$index=1;
while ($roundCount <= $players-1)
{
$matchCount = 1;
$round_set = 0;
for ($i=0; $i<=$this->MaxTeams/2; $i++) $this->mList[$i] = 0;
$startC = $roundCount;
while ($matchCount <= $players/2)
{
$c = $combinations + 1;
while ($c > $combinations)
{
$c = $startC;
/* find an unused pair that would be legitimate */
while (
($c <= $combinations)
&&
( //
($round_set & (1 << $this->cList[$c]['one'])) ||
($round_set & (1 << $this->cList[$c]['two'])) ||
(!empty($this->cUsed[$c]))
)
) $c++;
if ($c > $combinations)
{
do {
$this->mList[$matchCount] = 0;
$matchCount--;
$index--;
$round_set &= ~(1 << $this->cList[$this->mList[$matchCount]]['one']);
$round_set &= ~(1 << $this->cList[$this->mList[$matchCount]]['two']);
$this->cUsed[$this->mList[$matchCount]] = false;
$this->tourn[$index]['one'] = 0;
$this->tourn[$index]['two'] = 0;
}
while ($this->cList[$this->mList[$matchCount]]['one'] != $this->cList[$this->mList[$matchCount]+1]['one']);
$startC = $this->mList[$matchCount]+1;
}
}
$this->array_copy(&$this->tourn[$index],$this->cList[$c]);
$totalChecks++;
if (($totalChecks % 1000) == 0) printf("%d\033A\n", $totalChecks );
$this->cUsed[$c] = true;
$this->mList[$matchCount] = $c;
$startC = 1;
$round_set |= (1 << $this->cList[$c]['one']);
$round_set |= (1 << $this->cList[$c]['two']);
$index++;
$matchCount++;
}
$roundCount++;
}
/* yahoo!, scheduled all the rounds */
printf(" " );
$this->ShowSchedule($players,$totalChecks);
/* try and make a schedule using two more teams */
$players += 2;
}
}
}
?>
It's a PHP class. Reading the manual might help you.
Something along the lines of this might work:
$rr = new RoundRobin( 5 );
$rr->Scheldule( $_POST['PlayerCount'] );
But I can't be bothered deciphering the code to work out if it really will.
Also, if you haven't yet learnt HTML forms, read a tutorial like w3schools.