stijn0713 Posted July 6, 2012 Share Posted July 6, 2012 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 https://forums.phpfreaks.com/topic/265326--/ Share on other sites More sharing options...
NLT Posted July 6, 2012 Share Posted July 6, 2012 Use isset to check if it isn't empty first. <?PHP if(isset($_POST['Afloop_dag']) && $_POST['Afloop_dag'] == 1) { echo "selected"; } ?> Link to comment https://forums.phpfreaks.com/topic/265326--/#findComment-1359726 Share on other sites More sharing options...
ManiacDan Posted July 6, 2012 Share Posted July 6, 2012 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 https://forums.phpfreaks.com/topic/265326--/#findComment-1359727 Share on other sites More sharing options...
stijn0713 Posted July 9, 2012 Author Share Posted July 9, 2012 gracias, thought so! Link to comment https://forums.phpfreaks.com/topic/265326--/#findComment-1360298 Share on other sites More sharing options...
premiso Posted July 9, 2012 Share Posted July 9, 2012 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 https://forums.phpfreaks.com/topic/265326--/#findComment-1360313 Share on other sites More sharing options...
xyph Posted July 9, 2012 Share Posted July 9, 2012 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 Link to comment https://forums.phpfreaks.com/topic/265326--/#findComment-1360327 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.