Jump to content

Recommended Posts

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.  

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.

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.