Search code examples
phpmysqldatabasebindparam

Data not inserted but have no error PHP using bind_param


i have a simple code to input data to my database using prepare and bind_param

there is no error but my data are not inputted into database

  $stmt1 = $mysqli -> prepare ("INSERT INTO equipment(eqp_type, eqp_name, eqp_qty, eqp_usd, $eqp_idr) VALUES (?,?,?,?,?)");
  $stmt1->bind_param('sssss',$eqp_type, $eqp_name, $eqp_qty, $eqp_usd, eqp_idr);
  $eqp_type = 'BUC';
  $eqp_name = 'BUC test';
  $eqp_qty = '1';
  $eqp_usd = '0';
  $eqp_idr = '0';
  $stmt1->execute();

is there any idea why there is no error but my data are not inputted into database ?


Solution

  • You might forget to execute it.

    You can do it with following code:

    $stmt1->execute();
    

    So your code would look as follows:

    $eqp_type = 'BUC';
    $eqp_name = 'BUC test';
    $eqp_qty = '1';
    $eqp_usd = '0';
    $eqp_idr = '0';
    $stmt1 = $mysqli -> prepare ("INSERT INTO equipment(eqp_type, eqp_name, eqp_qty, eqp_usd, eqp_idr) VALUES (?,?,?,?,?)");
    $stmt1->bind_param('sssss',$eqp_type, $eqp_name, $eqp_qty, $eqp_usd, $eqp_idr);
    $stmt1->execute();
    

    Manual

    PHP: mysqli_stmt::bind_param