I have a really odd issue.
This is my code, as-is:
<?php
$cur = file_get_contents("./req.txt");
if(($_POST['bid'] >= $cur + 0.25) & $_POST['contact'] !== '')
{
$fi2 = "./req.txt";
file_put_contents($fi2, $_POST['bid']);
echo "<font color=\"red\" size=\"5\">Success</font>";
}
else
{
echo "<font color=\"red\" size=\"5\">Error.</font>";
}
?>
When it's like that, it works fine.
But, if I change the else
to if($_POST['bid'] >= $cur + 0.25)
(which is copied and pasted from above), the page loads fine and it doesn't run the file_put_contents
, but it doesn't echo Error
. This is what the code looks like changed:
<?php
$cur = file_get_contents("./req.txt");
if(($_POST['bid'] >= $cur + 0.25) & $_POST['contact'] !== '')
{
$fi2 = "./req.txt";
file_put_contents($fi2, $_POST['bid']);
echo "<font color=\"red\" size=\"5\">Success</font>";
}
if($_POST['bid'] >= $cur + 0.25)
{
echo "<font color=\"red\" size=\"5\">Error.</font>";
}
?>
What am I doing wrong?
If $_POST['bid'] >= $cur + 0.25
is false
, then both your codes in the if won't be executed.
The first piece of code will come into the else
, but the second won't come into the second if
.
& is the bitwise and operator in PHP, which has higher precedence than the !== operator. Try replacing the & with &&.