Prepared Statement: Number of variables doesn't match number of parameters in prepared statement

前端 未结 2 638
生来不讨喜
生来不讨喜 2021-01-28 19:53

I know this question has been asked several times before but I don\'t see any problem with my code and yet I still get this error On my code which doesn\'t make sense at all.

2条回答
  •  难免孤独
    2021-01-28 20:16

    You try to bind 2 parameters to a query that does not have any parameters:

    $stmt = $db_conx->prepare("SELECT id, product_name FROM yt ORDER by id");
    $stmt->bind_param("is", $id, $product_name);
    

    You can only bind parameters if you define placeholders for them like this:

    $stmt = $db_conx->prepare("SELECT id, product_name FROM where id = ? or  product_name = ?");
    $stmt->bind_param("is", $id, $product_name);
    

    The ? denotes placeholders you can bind parameters to.

提交回复
热议问题