didster Posted April 3, 2008 Share Posted April 3, 2008 Hello, I am very new to PHP so appologies if the code is awful. I am sure that someone will give me a simple answer! I have also used a few lines to test for myself. I have an HTML form that passes the variable chkno[] through to the seperate PHP file. Chkno[] is an array of 3 checkbox buttons. <input type="checkbox" id="chkno" name="chkno[]" value="(Go)"/> <input type="checkbox" id="chkno" name="chkno[]" value="(No GO Sector)"/> <input type="checkbox" id="chkno" name="chkno[]" value="(No GO Full Form)"/> When I do not click any of the buttons, my little test at the bottom returns not empty!? Please can anyone help? $chknotest0 = $_POST['chkno'][0]; $chknotest1 = $_POST['chkno'][1]; $chknotest2 = $_POST['chkno'][2]; $chknotest=array("$chknotest0", "$chknotest1", "$chknotest2"); print_r($chknotest); if (empty($chknotest)) print_r($chknotest); else echo "not empty"; Quote Link to comment https://forums.phpfreaks.com/topic/99354-easy-question-for-a-newbie/ Share on other sites More sharing options...
lordfrikk Posted April 3, 2008 Share Posted April 3, 2008 There is no need to use double quotes when passing only variables: $chknotest=array($chknotest0, $chknotest1, $chknotest2); By the way, what are you trying to test with this little script? Quote Link to comment https://forums.phpfreaks.com/topic/99354-easy-question-for-a-newbie/#findComment-508366 Share on other sites More sharing options...
didster Posted April 3, 2008 Author Share Posted April 3, 2008 Thankyou, The return that I get is... Array ( [0] => [1] => [2] => ) not empty ... so even though there is nothing typed in the tick boxes, my test still returns not empty! My test is to determine that at least one of the tick boxes is pressed. It doesnt matter which one of the three. As I say, I am only a beginner so I am probably way off the mark, Thankyou for your help so far! Quote Link to comment https://forums.phpfreaks.com/topic/99354-easy-question-for-a-newbie/#findComment-508394 Share on other sites More sharing options...
didster Posted April 3, 2008 Author Share Posted April 3, 2008 The proper return... Array ( [0] => [1] => [2] => ) not empty Quote Link to comment https://forums.phpfreaks.com/topic/99354-easy-question-for-a-newbie/#findComment-508412 Share on other sites More sharing options...
didster Posted April 3, 2008 Author Share Posted April 3, 2008 Whats going off here!? Quote Link to comment https://forums.phpfreaks.com/topic/99354-easy-question-for-a-newbie/#findComment-508414 Share on other sites More sharing options...
wildteen88 Posted April 3, 2008 Share Posted April 3, 2008 Before using user input variables ($_GET, $_POST, $_COOKIE etc) you should always check to see if they exists first and apply some form of validation: if(isset($_POST['chkno']) && is_array($_POST['chkno'])) { $chknotest = $_POST['chkno']; print_r($chknotest); } else { echo '$_POST[\'chkno\'] empty'; } Quote Link to comment https://forums.phpfreaks.com/topic/99354-easy-question-for-a-newbie/#findComment-508588 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.