0

im trying to check if the row in table is empty and the session also in , can i know what im doing wrong here.

 if (empty($row['images']) && (!isset($_SESSION['picture']) || $_SESSION['picture'] == ''))

EDIT : posting the code as im trying to post some divisions based on the picture, and if there are no picture i post a demo. i hope i explained it right.

if (mysqli_multi_query($conn, $sql)) {
    do {
        if ($result = mysqli_store_result($conn)) {
            while ($row = mysqli_fetch_array($result)){
                if (empty($row['images']) && (!isset($_SESSION['picture']) || $_SESSION['picture'] == '')){
                    echo "<div>" ;
                    echo "                  <img src='images/logo.png' alt=""/>";
                    echo "                  <h1>This Is A Demo</h1>";
                    echo "                  <p>This is a Demo paragraph .</p>";
                    echo"                   <a href='../go_back.php'>Demo</a>";
                    echo "</div>" ;
                } else{
                    echo "<div>" ;
                    if(!empty($row['images'])) {
                        echo "                  <img src='images/users_iamge.png' alt=""/>";
                        echo "                  <h1>Not Demo</h1>";
                        echo "                  <p>This is Not Demo paragraph .</p>";
                    }else{ // fetch the session
                        echo "                  <img src='images/users_iamge.png' alt=""/>";
                        echo "                  <h1>Not Demo</h1>";
                        echo "                  <p>This is Not Demo paragraph .</p>";
                    }
                }       
                echo'<h1>' 
                echo'<p>'
                echo "</div>";                  
            }
            mysqli_free_result($result);
        }   
    } while (mysqli_more_result($conn));
}
5
  • 3
    Without more context we cannot help you. This looks ok. Commented Dec 13, 2016 at 21:50
  • i have no errors in error log, but this is a condition i added to the code and its not working, thank you for your validation Commented Dec 13, 2016 at 21:54
  • 1
    But what are you trying to achieve, @Mavia? context is missing... it's not clear what you are asking Commented Dec 13, 2016 at 21:54
  • we'll its proper syntax, we just don't know the business logic on this side Commented Dec 13, 2016 at 22:02
  • i have edited my question, and sorry for any lack of information Commented Dec 13, 2016 at 22:09

1 Answer 1

1

Your logic appears to be wrong. Recapping basic operators in php.

The second condition in an or is only evaluated if the first condition evaluates to false.

Hence if $_SESSION['picture'] is set, the evaluation of $_SESSION['picture'] == '' will never occur (as the first condition of the or evaluates to true).

To get the functionality you desire (truetable below)

Empty  | SEmpty  | SNull  | Result
-------+---------+--------+---------
  0        0         0        0
  0        0         1        0
  0        1         0        0
  0        1         0        0
  1        0         0        0
  1        0         1        1
  1        1         0        1
  1        1         1        1

You need:

if( empty($row['images']) && 
       ( (isset($_SESSION['picture']) && $_SESSION['picture'] == '') ||
         !isset($_SESSION['picture']) ) 
  )
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.