PDO Duplicate Data Update Problem

0

I'm having a problem updating if I remove ! from if (!empty($data['slug'])) the code just does not work, and if I leave ! it simply says that there is its own value without changing any detail, could someone please help me.

if (!empty($_POST)) {

    $id = $_POST['id'];
    unset($_POST['id']);

    foreach ($_POST as $k => $v) {
        if (empty($_POST[$k])) {
            $_POST[$k] = null;
        }
    }

    $data = $_POST;

    if (!empty($data['slug'])) {
        $slug  = $data['slug'];
        $slugs = $db->prepare("SELECT count(id) FROM files WHERE slug = '$slug'");
        $slugs->execute();
        if (count($slugs->fetchColumn()) == "1") {
            $html->error('Slug Already Exists!')->GoBack(true);
        }
    }

    $db->update('files', $data, array(
        'id' => $id
    ));
    $html->success('Link Successfully Updated!')->Redirect('index.php', true);
}
    
asked by anonymous 11.12.2018 / 19:12

0 answers