Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 为什么要执行此代码?_Php_Html - Fatal编程技术网

Php 为什么要执行此代码?

Php 为什么要执行此代码?,php,html,Php,Html,看来最后一段越来越难了 所以我有if语句,在这些语句中,如果它们是真的,代码应该执行。问题是代码正在执行,即使它不是真的 即使Spproved设置为1也会执行的代码 if($user_data['permissions'] >= 1) { // If users permission is 1 or 2 they get a field for inputting the index # and a button to change the approve field from 0

看来最后一段越来越难了

所以我有if语句,在这些语句中,如果它们是真的,代码应该执行。问题是代码正在执行,即使它不是真的

即使Spproved设置为1也会执行的代码

if($user_data['permissions'] >= 1)
{
    // If users permission is 1 or 2 they get a field for inputting the index # and a button to change the approve field from 0 to 1 may need to make a new field to record who approved it....

    //Determine if the order is already approved.  If not approved show index field and allow user to approve it with index number
    if($data2[0]['Approved'] == 1)
    {
        echo " <font color=\"green\"> Approved";
    }
    else if($data2[0]['Approved'] == 0)
    {
        echo " Not Approved.  Supply an index number and click approve to authorize this order to be completed.";

        if (empty ($_GET) === false) 
        {
            $required_fields = array('IndexNum');
            foreach ($_GET as $key=>$value)
            {
                if (empty($value) && in_array($key, $required_fields) === true)
                {
                $errors[] = 'Fields marked with an asterisk are required';
                break 1;
                }
            }

            if (isset($_GET['success']) === true && empty($_GET['success']) === true)
            {            
                echo 'Index has been updated and Order is now set to Approved';
            }
            else
            {    
                if (empty($errors) === true)
                {   
                    $indexnum=$_GET['IndexNum'];
                    $approvedby=$user_data['lname'];
                    $vendorid1= $_GET['hidden1'];

                    update_approved($approvedby, $indexnum, $vendorid1);
                    header('Location: index.php');
                    exit();        
                }
                else if(empty($errors) === false)
                {
                    echo output_errors($errors);
                }
            }
        }

        ?>            
         <form name="approveform" method="GET" action="">
        <input type="hidden" name="hidden1" value="<?php echo $id;?>">"
        Index Number*: <input type="text" name="IndexNum">&nbsp;
        <input type="submit" value="Approve" action="">
        </form>

<?php }     
}

if($user_data['permissions'] == 2)
{
    // If user is permission 2 they can have a button to say shipped... Do I need to record who shipped it?  for now nah.  Would be nice to input a data of arrival though.  I will think on it .... pretty lazy
    if($data2[0]['Approved'] == 1)
    {
    echo "<br/>";
    echo "Confirm order has been ordered";

    if(isset($_GET['Ordered']))
    {
        $vendorid1=$_GET['hidden1'];

        echo $vendorid1;
        //update_shipped($vendorid1);
        //header('Location: index.php');
        //exit();
    }    
    ?>

    <form name="approveform" method="GET" action="">
    <input type="hidden" name="hidden1" value="<?php echo $id;?>">
    <input type="submit" name="Ordered" value="Ordered" action="">
    </form>

    <?php            
    }    
}    
使用严格的比较,==和!==而不是==和!=。除非另有明确说明,否则PHP倾向于将1和0计算为布尔值

此外,使用诸如empty之类的函数,您可以更改:

如果为空$\u GET==如果为假!空美元 if empty$\u GET==TRUE到if empty$\u GET

当它们返回布尔值时


由于您正在使用$\u GET,请确保每次传递所需的所有变量都在url中。由于表单元素只能传递嵌套的输入元素,因此在提交后可能需要传递更多隐藏信息。此外,您可能应该将文件名设置为action=或从表单标记中省略它。

我知道这不会解决您的问题,但是

                                                         You have an extra "
                                                             right here
                                                                  |
                                                                  V
    <input type="hidden" name="hidden1" value="<?php echo $id;?>">"
    Index Number*: <input type="text" name="IndexNum">&nbsp;
    <input type="submit" value="Approve" action="">

显示print_r$data2.Array[0]=>Array[VendorName]=>Newegg[DateRequested]=>2013-09-25[DateNeeded]=>0000-00-00[Shipping]=>Standard[VendorNumber]=>123123[VendorFax]=>NA[VendorAddress]=>1 ave new[VendorCity]=>socorro[VendorState]=>nm[VendorZip]=>87114[equipment耗材]=>耗材[GasType]=>丙烷[GasLocation]=>美国[UNMTag]=>0[EquipmentLocation]=>414141[totalcost]=>129.88[Approved]=>1[Shipped]=>0您所拥有的是一个逻辑错误。一步一步地调试每一个条件和任务,你就会得到答案。没有理由让其他人帮你这么做。很确定这不是一个逻辑错误,我认为杰森是对的。谢谢你的帮助input@HELPMEPLEASE您使用了错误的比较运算符。这是一个逻辑错误。vs。阅读有关调试逻辑错误的部分。查找此类错误的方法之一是将程序变量输出到文件或屏幕上,以便在代码中定义错误的位置。听起来和这里发生的事情一模一样。或者只是空的$\u getOK,虽然它修复了它,但似乎没有。它对===的作用是显示正确的信息,但现在如果我使用submit按钮,它不会处理信息,只会返回页面。在添加===之前,Approveform所使用的两个函数中都会出现这种情况。现在,两个表单在提交时都进入一个空白页,这样就缩小了范围@斯诺伯恩:我说的是第一个使用整数的条件,它们都在URL中。我将为你上传一些图片。我真的不知道为什么这不起作用。你也使用$u GET['success',这看起来与任何事情都没有关系。噢,谢谢!我没看到。
                                                         You have an extra "
                                                             right here
                                                                  |
                                                                  V
    <input type="hidden" name="hidden1" value="<?php echo $id;?>">"
    Index Number*: <input type="text" name="IndexNum">&nbsp;
    <input type="submit" value="Approve" action="">