简体   繁体   中英

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 ?

You have to execute your query using

$stmt1->execute();

Read here: http://php.net/manual/en/pdostatement.execute.php

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

你需要添加$stmt1->execute() ,你会得到错误,因为你也错过了eqp_idr $

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM