1
if($_POST)
{

    if(array_key_exists("item_id", $_POST))   // asking if the array exists in data.php,
    {


        $item_ids = $_POST["item_id"];       // temp var. to hold the data.php data
        $price=0;
        foreach ($items as $item) 
        {
            foreach($item_ids as $value)
            {
                if($value==$item['id'])      //checking for the ids that were store in array
                 $price+=$item['price'];    // adds price of the ids that are selected
            }

        }
        require_once("view_confirm.php");   //shows the total of price in the view_confirm.php
        die();  


     //if there wasnt any selected boxes its set to true for a statement to be stated on view_items
    }
    $error_no_items_selected =true;
}

My function works, I have a problem displaying an error message when the there is no click boxes, I set the value to false above post, $error_items_selected, on my view_items.php is HTML code, where I also use:

<?php if(error_items_selected==true){echo "Click Something";}

every time I refresh the page the message already appears,

1
  • error_items_selected == true should be $error_items_selected == true Commented Oct 21, 2015 at 19:59

1 Answer 1

1

In

if(error_items_selected==true){echo "Click Something";}

error_items_selected should have a $ if it's a variable.

Or () if it's a function call.

If you use error_items_selected - PHP considers it a constant. And if you don't have such constant, that is obvious, error_items_selected is considered a 'error_items_selected' string which is definitely true.

So proper way should be:

if ($error_items_selected==true){echo "Click Something";}

Also in first code block you use $error_no_items_selected. Maybe it's just different variables, but still - check them.

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.