Jump to content

<?php if ($_POST['Afloop_dag'] == "1") { echo "selected"; } ?>


stijn0713

Recommended Posts

I thought i add this piece of code:

<?php if ($_POST['Afloop_dag'] == "1") { echo "selected"; } ?>

in my options, like:

 

<option value="1" <?php if ($_POST['Afloop_dag'] == "1") { echo "selected"; } ?>>1</option>.

 

However, now it says that Afloop_dag index is undefined. However, i used this before in a signup code and it worked. why does the index need to be defined? im using it in a if statement

Link to comment
Share on other sites

That's a standard error message, your code may not have had error reporting turned on before.

 

A more correct version is:

 

<?php if ( isset( $_POST['Afloop_dag'] ) && $_POST['Afloop_dag'] == "1") { echo "selected"; } ?>

-Dan

Link to comment
Share on other sites

Use isset to check if it isn't empty first.

 

I just felt like nit picking, if you want to check if it is not empty, use empty which will do an is set check as well. However, if you want to know if the variable has been previously set, and do not care if it is empty, false, null etc or not isset is the way to go.

Link to comment
Share on other sites

Use isset to check if it isn't empty first.

 

I just felt like nit picking, if you want to check if it is not empty, use empty which will do an is set check as well. However, if you want to know if the variable has been previously set, and do not care if it is empty, false, null etc or not isset is the way to go.

 

More nitpicking, isset will return FALSE if it's argument evaluates to NULL :D

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.