开发者

Is it a correct approach in php?

first of all this is my first post in stack <3 and of course sorry for my bad English. So i'm studying PHP and i have something like a problem in my mind:

when i write a code like:

if ($_POST['submit'])
{
    $total = $_POST["total"];
    $var = $_POST["var"];

function func($total, $var)
    {
     $lost = $total * $var / 100;
     $income = $total - $income;
     $result = "Income - " . $income . "<br />Lost - " . $lost;

     return $result;
    }

echo func($total, $var);
}
else
{
?>


<?php 
// HTML FORM : i write to number example total = 1000
// and var = 200 and result is 1000 - (1000/100*20)
?>
<form method="POST" action="index.php">
    <input type="text" name开发者_高级运维="total" />
    <input type="text" name="var" />

    <input type="submit" name="submit" value="Submit" />
</form>
<?php }?>

there is an error: Notice: Undefined index: submit when i search in google, i found a something like solution, error_reporting (E_ALL ^ E_NOTICE) but i think this is not a correct solution.


empty() and isset() are the tools you want in this situation

if (!empty($_POST['submit'])) {


I think its telling you that that $_POST['submit'] is not set ...

Try using this instead ..

if (array_key_exists('submit', $_POST)) {
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜