简体   繁体   中英

If Statement condition not being recognised despite being met

I have an if statement where the condition compares a session variable to the value 0 and if met, echo's a message. If not, it prints a table of data. The problem is that the condition, despite being met, is not being recognised. I have tested to make sure that the value of the session variable is being set and it is. It is used elsewhere on the page and definitely has a value set. Any idea's what might be wrong here?

*EDIT: There is a session start function at the beginning of the page.

<?php//if number of rows returned is none
        if($_SESSION["CART_NUM"] == 0){
        echo 'YOU HAVE NO ITEMS IN YOUR CART';
        }else{
    //else display cart items
    ?>

        <table id="cart">
            <tbody>
                <tr>
                    <td><h6>ITEM NAME</h6></td>
                    <td><h6>QTY</h6></td>
                    <td><h6>PRICE</h6></td>
                    <td><h6>TOTAL</h6></td>
                    <td><h6>DELETE</h6></td>
                </tr>
<?php
                //query DB again for cart items matching cust id
                $custcart = oci_parse($conn,"SELECT * FROM   
                A113222813_CARTLINE WHERE CUST_ID= :cust_id");
                oci_bind_by_name($custcart, ":cust_id", $_SESSION["CUST_ID"]);
                oci_execute($custcart);

                while ($row = oci_fetch_array($custcart, OCI_ASSOC)) {?>

                <tr class="cartvals">
                    <td><p><?php echo $row['CART_NAME']; ?></p></td>
                    <td><p><?php echo $row['PRICE']; ?></p></td>
                    <!--Form for updating quantity-->
                    <td><form class="updateform" method="post" id="form<?php echo $row['CART_ID'];?>" action="updatecart.php?id=<?php echo $row['CART_ID']; ?>">
                            <input type="text" name="qty" value="<?php echo $row['CART_QTY']; ?>">
                            <a href="javascript:{}" onclick="document.getElementById('form<?php echo $row['CART_ID']; ?>').submit();">submit</a>
                        </form>
                    </td>
                    <td><p><?php echo '&euro;' . ($row['CART_QTY'] * $row['PRICE'])  ?></p></td>
                    <!--Appends cart_id as query string param. Deleteitem.php will get this as an id and delete corresponding row.-->
                    <td><a href="deleteitem.php?item=<?php echo   
                    $row['CART_ID']?>">DELETE</a></td>
                </tr>
<?php
}?>
            </tbody>
        </table>
    </div><!--End Cart Table-->
</div><!--End Main Content-->
<?php

oci_close($conn);
?> 

SOLVED:

The line <?php//if number of rows returned is none had the comment touching the tag. Spaced it's working again.

Thanks for taking a look anyway!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM