PHP:当我使用post时,会触发if和else语句

时间:2014-05-28 17:51:19

标签: php

当我使用$ _POST时,if和else语句都被执行。但奇怪的是,只有foreach循环被执行,而#34; Flag是0"被打印到屏幕上。如果我用$ Flag = 0替换$ Flag = 1,则在else语句中,循环不会被执行。当我更换" isset($ _ POST [' Back'])"使用" 1",再次循环不执行,一切都很好。那么当我使用$ _POST时,为什么我的else和if语句都会执行?感谢您的任何输入

档案#1

$Flag = 0;
    if (isset($_POST['Back']))
    { echo "Flag is 0";
        $Value = sqlsrv_fetch_array(sqlsrv_query($dbhandle,'SELECT MAX([Protocol Branch]) FROM Import_Trial_Information'),SQLSRV_FETCH_NUMERIC);
        $Value = $Value[0];
    }               
    else {$Flag = 1; echo "Flag is 1"; }

    if ($Flag)
    { 
        foreach ($Database_Tables AS $Delete)
        {
            $Query = 'DELETE FROM Import_' . $Delete;
            sqlsrv_query($dbhandle,$Query);
            if ($Delete == 'Paper_Information') {$Protocol = array('','');}
            else {$Protocol = array(',[Protocol Branch]',',1');}
            $Query = 'INSERT INTO Import_' . $Delete . '([Paper ID]' . $Protocol[0] . ') VALUES (' . (string)$ID . $Protocol[1] .')';
            sqlsrv_query($dbhandle,$Query);
        } 
        $Value = 1;
    }

档案#2

<div id = "Back_Button">
<form action="Import_Article_Advanced.php" method = "POST"><button name = "Back" ID = "Back" Value = "Back">Return to Previous Page</button></form>
</div>

1 个答案:

答案 0 :(得分:0)

试试这个

  if (isset($_POST['Back']) OR !empty($_POST['Back']) OR $_POST['Back']!="" )
 { echo "Flag is 0";
    $Value = sqlsrv_fetch_array(sqlsrv_query($dbhandle,'SELECT MAX([Protocol Branch]) FROM        Import_Trial_Information'),SQLSRV_FETCH_NUMERIC);
    $Value = $Value[0];
}               
else {$Flag = 1; echo "Flag is 1"; }