Uncaught Error: Call to a member function bind_param() on bool in
Publicado por Angel (12 intervenciones) el 16/09/2020 12:14:46
Buenas, estoy haciendo un proyecto con js, php, ajax y mysql y recibo este error al intentar subir un registro de php a mysql: Uncaught Error: Uncaught Error: Call to a member function bind_param() on bool in C:\xampp\htdocs\Nueva carpeta\modelo-contactos.php:12.
Codigo PHP que da el error
Codigo JS con AJAX
Codigo PHP que da el error
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php
require_once("conexionbd.php");
$usuario = filter_var($_POST['nombre'], FILTER_SANITIZE_STRING);
$empresa = filter_var($_POST['empresa'], FILTER_SANITIZE_STRING);
$telefono = filter_var($_POST['telefono'], FILTER_SANITIZE_STRING);
echo("$usuario $empresa $telefono");
try {
$statement = $conexion->prepare("INSERT INTO agendatareas(usuario, empresa, telefono) VALUES (?,?,?)");
$statement -> bind_param("sss", $usuario, $empresa, $telefono);
$statement->close();
$conexion->close();
} catch (Exception $e) {
console.error($e->getMessage());
}
?>
Codigo JS con AJAX
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const form = document.getElementById('añadircontactos').addEventListener("submit", leerformulario);
function leerformulario(evt) {
const nombre = document.getElementById('nombre').value;
const empresa = document.getElementById('empresa').value;
const telefono = document.getElementById('telefono').value;
var infocontacto = new FormData();
infocontacto.append('nombre', nombre);
infocontacto.append('empresa', empresa);
infocontacto.append('telefono', telefono);
if (nombre == "" || empresa == "" || telefono == "") {
console.log('Todos los campos son obligatorios')
} else {
insertardb(infocontacto);
}
evt.preventDefault();
}
function insertardb(datos) {
let xhr = new XMLHttpRequest();
xhr.open("POST", "modelo-contactos.php", true);
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
var respuesta = xhr.responseText;
console.log(respuesta)
}
}
xhr.send(datos);
}
Valora esta pregunta


0