PHP - subir datos de un form a base myql

 
Vista:

subir datos de un form a base myql

Publicado por ismael (15 intervenciones) el 21/12/2017 17:58:44
Call to a member function bind_param() on boolean

Pues este es el error que no consigo solucionar. He hecho un ejemplo sencillo de mi script para que sea mas legible. Se trata de un form(index.php que se envia a subirBase.php que a su vez llama a una clase base.php. Estoy seguro que usuario, password y base son correctos. Se agradece la ayuda.

index.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<!DOCTYPE html>
<html>
<head>
	<title></title>
</head>
<body>
 
<form name="registroUsuarios" method="post" action="subirBase.php">
  <label>Introduce titulo</label>
  <input type="text" size="60" name="txt"/><br>
 
  <input type="submit" value="registrar">
  <input type="reset" value="limpiar">
 
</form>
 
</body>
</html>

subirBase.php

1
2
3
4
5
6
7
8
9
10
11
<?php
include('base.php');
 
 
$a = $_POST['txt'];
 
$subirDatos = new manejadorBase('localhost','root','1234','basepruebas');
$subirDatos->introducirDatos($a);
$subirDatos->desconectar();
 
?>

base.php

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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
class ManejadorBase{
    private $localhost;
    private $usuario;
    private $contrasena;
    private $base;
    private $titulo;
    private $db;
 
 
    function _construct($localhost, $usuario, $contrasena, $base){
 
       $this->localhost = $localhost;
       $this->usuario= $usuario;
       $this->contrasena ->$contrasena;
       $this->base -> $base;
 
    }
 
    function conectar(){
        @$this->db = new mysqli($this->localhost, $this->usuario, $this->contrasena, $this->base);
 
        if(mysqli_connect_errno()){
          	$this->setControl(0);
          	echo '<p>Parece que hay un problema con nuestra base. Please, intentalo mas tarde</p>';
          	exit;
        }
    }
    function introducirDatos($titulo){
 
        $this->conectar();
 
        $this->titulo = $titulo;
 
        $this->query = "insert into libro(titulo) values(?)";
        $this->stmp = $this->db->prepare($this->query);
        $this->stmp->bind_param('s', $this->titulo);
        $this->stmp->execute();
 
 
        if($this->stmp->affected_rows >0){
          	echo '<p>Ya estas registado</p>';
          	echo '<p>Te hemos enviado un mail para activar tu cuenta</p>';
        }else{
          	echo '<p>Algun error ha ocurrido. Intentalo más tarde</p>';
        }
        $this->stmp->close();
 
    }
    function desconectar(){
 
        $this->db->closed();
 
    }
 
}
 
}
 
?>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

subir datos de un form a base myql

Publicado por isma (15 intervenciones) el 21/12/2017 19:07:06
lo tengo como en la documentación. Está el interrogante y luego en la funcion ponemos s. te refieres a eso, no?

1
2
3
4
5
$this->query = "insert into libro(titulo) values(?)";
 
$this->stmp = $this->db->prepare($this->query);
 
$this->stmp->bind_param('s', $this->titulo);
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

subir datos de un form a base myql

Publicado por ismael (15 intervenciones) el 21/12/2017 22:21:18
Ya esta solucionado. hay un monton de fallos en el script pero basicamente el error referido al bind_param estabá en el constructor. Es lo malo de ser novato... Gracias por la ayuda!!!
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar