0

error

I have a big problem it keeps telling me this while I check everything and everything is good here is the code of the page in question. If I'm ever currently training that dates back 7 years so I think some thing doesn't work anymore so can be that the mistake comes from the.

include '../lib/includes.php';

if(isset($_POST['name']) && isset($_POST['slug'])){
    checkCsrf();
    $slug = $_POST['slug'];
    if(preg_match('/^[a-z\-0-9]+$/', $slug)){
        $name = $db->quote($_POST['name']);
        $slug = $db->quote($_POST['slug']);
        $category_id = $db->quote($_POST['category_id']);
        $content = $db->quote($_POST['content']);
        if(isset($_GET['id'])){
          $id = $db->quote($_GET['id']);
          $db->query("UPDATE works SET name=$name, slug=$slug, content=$content, category_id=$category_id WHERE id=$id");
        }else {
          $db->query("INSERT INTO works SET name=$name, slug=$slug, content=$content, category_id=$category_id");
        }
        setFlash("La réalisation a bien été ajouté", 'success');
        //header('Location:work.php');
        die();
    }else {
        setFlash("Le slug n'est pas valide", 'danger');
    }
}

if(isset($_GET['id'])){
  $id = $db->quote($_GET['id']);
  $select = $db->query("SELECT * FROM works WHERE id=$id");
  if($select->rowCount() == 0){
    setFlash("Il n'y a pas de réalisation avec cet ID", 'danger');
    header('Location:work.php');
    die();
  }
  $_POST = $select->fetch();

}

$select = $db->query('SELECT id, name FROM categories ORDER BY name ASC');
$categories = $select->fetchAll();
$categories_list = array();
foreach($categories as $category){
    $categories_list[$category['id']] = $category['name'];
}

include '../partials/admin_header.php';
?>```
rickdenhaan
  • 10,857
  • 28
  • 37
  • I don't know what `$db->quote` is doing but if it is actually quoting it then it is a string instead of an integer and that's your problem. – AbraCadaver Jan 11 '21 at 00:26
  • What is the value of `$_POST['category_id']`? According to the error message, it is the literal string `"id"` where your database expects a number. – rickdenhaan Jan 11 '21 at 00:42
  • Please add all error messages in text form, along with your debugging attempts – Nico Haase Feb 19 '21 at 07:26

0 Answers0