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

前端 未结 2 602
生来不讨喜
生来不讨喜 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.

    0 讨论(0)
  • 2021-01-28 20:23

    you are binding the parameter "is" which doesn't exist in your sql statement edit: and you dont have any "?" placeholders either

    msqli_stmt::bind_param

    0 讨论(0)
提交回复
热议问题