0

After creating new database and importing old from backup, I cannot insert new records , only updating already entered records. I use procedural statement , here is current code

$servername = "localhost:3306";
$username = ".....";
$password = "......";
$dBname = ".......";

$conn = new mysqli($servername, $username, $password, $dBname);
$conn->set_charset("utf8");


$stmt = $conn -> prepare("INSERT INTO tbl_cat (broj2,broj1,hide,broj4) VALUES (?,?,?,?) "); 
    
$stmt -> bind_param('ssss',$var_type,$var_level,$var_hide,$total); 

$stmt -> execute(); 
$stmt-> store_result(); 

Dharman
  • 30,962
  • 25
  • 85
  • 135
Deko
  • 1
  • Mysqli does not explicitly throw errors, so you have to check `$conn->error` to see what is going on. You could check the value of `$stmt->execute()` and if it returns false, then echo the `$conn->error` like so `if(!$stmt->execute()){echo $conn->error; exit();}` to see what errors you have – Ant Jun 12 '21 at 23:18
  • @Ant Mysqli throws errors. Checking manually for them is bad practice – Dharman Jun 12 '21 at 23:37
  • You can't call `store_result` on `INSERT` There's no result to store – Dharman Jun 12 '21 at 23:37
  • `utf8` charset is depreacted for the past 11 years. Please use `utf8mb4` – Dharman Jun 12 '21 at 23:38
  • If you are only starting to learn PHP then you should learn PDO instead of mysqli. PDO is much easier and more suitable for beginners. Start here https://phpdelusions.net/pdo & https://websitebeaver.com/php-pdo-prepared-statements-to-prevent-sql-injection – Dharman Jun 12 '21 at 23:38
  • @Dharman while it does throw some errors, it does not halt on issues like Syntax errors. Also I have never heard of it being a bad practice of manually checking for error, could you provide some insight into that? All the example code in php's manual include manual checks after execution – Ant Jun 12 '21 at 23:42
  • @Ant The manual shows how to enable automatic error reporting. Mysqli reports automatically all errors that you would normally check manually. Manual checking is redundant and inconvenient. This post explains it well https://stackoverflow.com/questions/22662488/mysqli-fetch-assoc-expects-parameter-call-to-a-member-function-bind-param – Dharman Jun 13 '21 at 00:13

0 Answers0