0

i have this checkbox input in my form

<input name='new' type='checkbox' value='0' />

the column new in my database is TINYINT based on the value of the checkbox , i want to display a div with a class if the value is 1 so i implement this code

if(isset($_POST[$URL['new']]) 
   && isset($_POST[$URL['new']]) == 1)
   {
    echo '<div class="premiere">Premiere</div>';
    }

everything seems working fine , there's no error,warnings and notices.but the div didnot display in the page . what is wrong with the code and how i can fix it? thanks

8
  • 3
    Why are you using $URL['new']? Commented Dec 24, 2012 at 6:19
  • the is the name i gave the array element like that i have it <?php foreach ($URLS as $URL).i can change it Commented Dec 24, 2012 at 6:23
  • $_POST["new"] is enough Commented Dec 24, 2012 at 6:25
  • @ObedLorisson if you are using foreach, $URL is the key. It is not an array. so you cannot call it as $_POST[$URL['new']] if you need more help let us know what you really going to do. Commented Dec 24, 2012 at 6:32
  • yeah true , it's the key, i change the syntax , still not displaying Commented Dec 24, 2012 at 6:36

5 Answers 5

2
if ( isset($_POST["new"]) && $_POST["new"] == 1 )
{
  echo '<div class="premiere">Premiere</div>';
}
Sign up to request clarification or add additional context in comments.

Comments

0

i think, you have apply second condition to check value of "new" variable.

you should write condition like this

if(isset($_POST[$URL['new']]) && $_POST[$URL['new']] == 1){
}
else{
}

Comments

0
if ( isset($_POST["new"]) && $_POST["new"] == 1 )
{
  echo '<div class="premiere">Premiere</div>';
}

Make sure class "premiere" not hidden through css code.

Comments

0

You can use this query to display div on checking the checkbox and on unchecking checkbox you can hide the div displayed.

    $(document).ready(function(){
     $("#new").change(function(e){
     var addDiv = $("#new").val();
     if($("#new").attr('checked'))
      { 
       $("#form2").append("<div class="premiere">Premiere</div>");
      }
      else
      {
       $(".premiere").remove();
      }
     });
    });

HTML Code:

    <form method="post" id="form2">
    <input id="new" name='new' type='checkbox'/>
    </form>

Hoping that this post will be very much useful to you.

Comments

0

The prob was , i was trying to access the key from an array in a foreach loops , so i just remove the $_POST from the key and reference like URL['new'] instead. and it works fine.

if(isset($URL['new']) 
   && isset($URL['new']) == 1)
      {
  echo '<div class="new">Premiere</div>';
   }

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.