-1

好像最后一段越来越难了!

所以我有 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            
    }    
}    

IT 在表单上以绿色显示 Approved 并且 Ordered 按钮正常显示。当我单击提交按钮时,else if($data[0]['Approved'] == 0) 中的代码将激活,而不是 isset 中的代码。Approved 设置为 1 所以我不知道为什么该代码正在运行.....

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 [EquipmentConsumable] => Consumable 
[GasType] => propane [GasLocation] => United States [UNMTag] => 0 
[EquipmentLocation] => [index] => 414141 [totalcost] => 129.88 
[Approved] => 1 [Shipped] => 0 ) ) 
4

2 回答 2

1

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

                                                         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="">
于 2013-09-26T21:02:58.847 回答
1

使用严格比较,===!==不是==and !=。除非另有明确说明,否则 PHP 倾向于将 1 和 0 评估为布尔值。

此外,使用类似的功能empty(),您可以更改:

if( empty($_GET) === FALSE ) if( !empty( $_GET ) )
if( empty($_GET) === TRUE ) _ if( empty( $_GET ) )

当他们返回布尔值时。

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

于 2013-09-26T19:44:07.723 回答