0

Returns an error and does not delete the entry, what could be the problem?

  public function del(){
      echo "<h1>DEL</h1> method of ".get_class($this);
      $params = explode("?", $_SERVER["REQUEST_URI"]);  
      $params = $params[1]; 
      parse_str($params, $arr);
      vd($arr);
      $mysqli = new \mysqli("localhost", "root", "", "quest"); 
      $mysqli -> query ("DELETE FROM users WHERE id = '{$arr["id"]}'");
    }
MegaRoks
  • 898
  • 2
  • 13
  • 30

1 Answers1

1

I think you have an syntax error in your delete line:

$mysqli->query(sprintf("DELETE FROM users WHERE id = %d", $arr["id"]));

you quotes are not correct. Normally you should use prepared statements but to get your code work you can use sprintf and be sure that you have a number in your delete statement.

René Höhle
  • 26,716
  • 22
  • 73
  • 82
  • I changed the request to suggested, when typing in the address bar it does not delete the entry with id 18, but gives an error. Fatal error: Uncaught Exception: Error! Warning! Achtung! Danger! in /home/cabox/workspace/core/FactoryRouting.class.php:35 Stack trace: #0 /home/cabox/workspace/index.php(32): core\FactoryRouting::getController('/news/del&id=18') #1 {main} thrown in /home/cabox/workspace/core/FactoryRouting.class.php on line 35 – MegaRoks Oct 09 '17 at 16:19