Problems using INSERT in PHP (mysqli)

0

I (beginner in the php development area) I'm having trouble inserting data using the code below:

    <?php

$conn = new mysqli("zz", "zz", "zz", "zz"); 
// Alterei a string de conexão por questão de segurança

if ($conn->connect_error) {
  echo "Error: " .$conn->connect_error;
}

$login = 'user';
$senha = '12345';
$stmt = $conn->prepare("INSERT INTO tbl_usuario (login,senha) VALUES (?, ?)");
$stmt->execute();
?>

It runs normally, with no error, but when I check my database, no data was actually included: /. Could someone help me?

Follow the bank's printout:

    
asked by anonymous 04.10.2018 / 15:48

1 answer

1

After creating Prepared Statement , you must bind of values:

$stmt->bind_param("ss", $login, $senha);

Otherwise nothing is executed:

<?php
    $conn = new mysqli("zz", "zz", "zz", "zz"); 
    // Alterei a string de conexão por questão de segurança

    if ($conn->connect_error) {
      echo "Error: " .$conn->connect_error;
    }

    $login = "user";
    $senha = "12345";
    $stmt = $conn->prepare("INSERT INTO tbl_usuario (login,senha) VALUES (?, ?)");
    $stmt->bind_param("ss", $login, $senha);
    $stmt->execute();
?>
    
04.10.2018 / 15:54