I have started learning PHP relatively recently and in the process I am trying to insert the data of a form into a database using PHP as I have been looking at a safe way by means of ready statements and objects and so I am trying it even though I am not if it is the correct form I enclose the data insertion code.
<?php
include('conexion.php');
if (isset($_POST['submit'])) {
$codLibro=$_POST['codLibro'];
$importe=$_POST['importe'];
$tipoMoneda=$_POST['tipoMoneda'];
$peticion="INSERT INTO ejemplares (codLibro,importe,tipoMoneda)
VALUES (?, ?, ?)";
$stmt = $conn->prepare($peticion);
$stmt->bind_param('dds', $codLibro, $importe, $tipoMoneda);
$stmt->execute();
$stmt->close();
echo "Registro Insertado";
$conn->close();
}
?>
Here I put my PHP file of connection to the Database
Below is my form for sending data in HTML
<form action="addejemplares.php" method="POST">
<div class="form-group">
<div class="col-xs-2">
<label for="codLibro">codLibro:</label>
<input type="text" class="form-control" name="codLibro" id="codLibro">
<label for="importe">importe:</label>
<input type="text" class="form-control" name="importe" id="importe">
<label for="tipoMoneda">tipoMoneda:</label>
<input type="text" class="form-control" name="tipoMoneda" id="tipoMoneda">
<button type="submit" class="btn btn-default" name="submit">Submit</button>
</div>
</div>
</form>
As you can see, a simple submission form and then I attached an image of the table to which I want to insert data
And finally I enclose an image of the errors that PHP is taking me First of all thank you very much in advance to the entire community.
Connection
<?php
$conn = new mysqli("localhost", "root", "", "bdBiblioteca");
if (mysqli_connect_errno()) {
die("No se puede conectar a la base de datos:" . mysqli_connect_error());
}else{
echo "conexion exitosa";
}
$conn->close();
?>