Jump to content

php intigar compair


Shakhawat

Recommended Posts

i am new php learner . i need help from group to learn batter php program.
i cannot create solve this help me please .

my code:
html:
<form action="chake.php" method="post">

<input type="number" name="one" placeholder="enter your number" required />
<input type="number" name="two" placeholder="enter your number" required />
<input type="submit" value ="enter"/>

</form>
php:
<?php
$left_operand =$_POST["one"];
$right_operand =$_POST["two"];

$output =bccomp($right_operand ,$right_operand);
if($output == 0){
echo 'equal';
}
elseif ($output > 0){
echo $right_operand.' is biger then '.$left_operand;
}
else{
echo $left_operand.' is bigger then '.$right_operand ;
}

?>

 

 

Link to comment
Share on other sites

Should you not be comparing $left_operand with $right_operand here?

$output =bccomp($right_operand ,$right_operand);

As it is you are comparing $right_operand with $right_operand

 

Also you have the variables in the wrong way round in the echo statements

elseif ($output > 0){
echo $right_operand.' is biger then '.$left_operand;
}
else{
echo $left_operand.' is bigger then '.$right_operand ;
}

They should be the other way round. Quote from php.net

 

 

Return Values

Returns 0 if the two operands are equal, 1 if the left_operand is larger than the right_operand, -1 otherwise.

That is saying if $left_operand is greater then $right_operand it will return 1, otherwise it will return -1 if $right_operand is greater then $left_operand.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.