nextgen Posted August 9, 2022 Share Posted August 9, 2022 Friends i have a had a few rough years and when i get back home i started to tinker with my old website. I have cleared a ton of deprecation errors etc but the last 2 have me stumped as i am not a coder i was an electrician. Here is my code. $nfield = $_POST[nfield]; if (count($nfield) > 0) { foreach ($nfield as $key => $var) { $var = check_html($var, "nohtml"); $var = trim(htmlspecialchars($var, ENT_QUOTES)); $nfield[$key] = $var; } } Please, if anyone can help i would appreciate it. Quote Link to comment https://forums.phpfreaks.com/topic/315157-warning-tells-me-that-count-needs-to-be-an-array/ Share on other sites More sharing options...
Barand Posted August 9, 2022 Share Posted August 9, 2022 Then $_POST['nfield'] is not an array as exepected. You need to check why. What is the form markup code where it originates? Quote Link to comment https://forums.phpfreaks.com/topic/315157-warning-tells-me-that-count-needs-to-be-an-array/#findComment-1599183 Share on other sites More sharing options...
dodgeitorelse3 Posted August 9, 2022 Share Posted August 9, 2022 (edited) The $_POST[nfield] should be $_POST['nfield'] Edited August 9, 2022 by dodgeitorelse3 Typo Quote Link to comment https://forums.phpfreaks.com/topic/315157-warning-tells-me-that-count-needs-to-be-an-array/#findComment-1599184 Share on other sites More sharing options...
nextgen Posted August 9, 2022 Author Share Posted August 9, 2022 usercp_register.txt The issue is from line 94 of the above text which is stopping users from registering on my site Quote Link to comment https://forums.phpfreaks.com/topic/315157-warning-tells-me-that-count-needs-to-be-an-array/#findComment-1599188 Share on other sites More sharing options...
kicken Posted August 9, 2022 Share Posted August 9, 2022 The usual cause in a scenario like this is that your $_POST['nfield'] input simply doesn't exist and as such $nfield would be null and not an array. You could use the null-coalescing operator to handle that. $nfield = $_POST['nfield'] ?? []; If that were the case and you have your error reporting turned up fully, you should also be getting errors regarding 'Undefined index: nfield' (and in your case, warnings about an undefined constant since you don't have quotes around the key name). Do a simple var_dump($_POST['nfield']) prior to that line and you can see what the field is and use that to determine how it should be fixed. Quote Link to comment https://forums.phpfreaks.com/topic/315157-warning-tells-me-that-count-needs-to-be-an-array/#findComment-1599192 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.