error al tratar de hacer un inserción en php mysql, quien porfavor me ayuda
Publicado por gary pacheco (2 intervenciones) el 19/04/2017 17:57:06
Archivo conexion.php
archivo controllerEmpleado.php
archivo modelEmpleado.php
viewEmpleado.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
<?php
class conexion{
private $host;
private $user;
private $pass;
private $db;
public function __construct(){
try {
$this->host="127.0.0.1";
$this->user="root";
$this->pass="root";
$this->db="prueba";
$conexion=mysqli_connect($this->host,$this->user,$this->pass);
if ($conexion->connect_errno) {
return false;
}else{
mysqli_select_db($conexion, $this->db) or die('Error al seleccionar Base de datos');
echo "conexion establecida";
}
} catch (Exception $e) {
}
}
function get_query($sql){
mysqli_query($sql);
}
function set_query($sql){
mysqli_query();
return ;
}
}
?>
archivo controllerEmpleado.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
<?php
include_once("modelEmpleado.php");
class controllerEmpleado{
//Atributos
private $empleado;
//Metodos
public function __construct(){
$this->empleado=new modelEmpleado();
}
public function crear($cc, $nombre, $correo, $fecha_nac, $sexo, $area_trab, $cargo, $fecha_ingr){
$this->empleado->$cc=$cc;
$this->empleado->$nombre=$nombre;
$this->empleado->$correo=$correo;
$this->empleado->$fecha_nac=$fecha_nac;
$this->empleado->$sexo=$sexo;
$this->empleado->$area_trab= $area_trab;
$this->empleado->$cargo= $cargo;
$this->empleado->$fecha_ingr= $fecha_ingr;
$this->empleado->crear();
}
public function eliminar($id){
$this->estudiante->set("id", $id);
$this->estudiante->eliminar();
}
public function ver($id){
$this->estudiante->set("id", $id);
$datos = $this->estudiante->ver();
return $datos;
}
public function editar($id, $nombre, $apellido, $edad, $telefono){
$this->estudiante->set('id', $id);
$this->estudiante->set('nombre', $nombre);
$this->estudiante->set('apellido', $apellido);
$this->estudiante->set('edad', $edad);
$this->estudiante->set('telefono', $telefono);
$this->estudiante->editar();
}
}
?>
archivo modelEmpleado.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
61
62
63
64
<?php
//CLASE DE CONEXIÓN INCLUIDA
require_once('conexion.php');
class modelEmpleado{
//Atributos
private $cc;
private $nombre;
private $correo;
private $fecha_nac;
private $sexo;
private $area_trab;
private $cargo;
private $fecha_ingr;
//Metodos
public function crear(){
$cnx=new conexion();
$sql= "INSERT INTO empleados (cc, nombre, correo, fecha_nac, sexo, area_trab, cargo, fecha_ingr) VALUES (
{$this->cc}, '{$this->nombre}', '{$this->correo}', '{$this->fecha_nac}', '{$this->sexo}',
'{$this->area_trab}', '{$this->cargo}','{$this->fecha_ingr}')";
$cnx->set_query($sql);
}
public function eliminar(){
$sql = "DELETE FROM estudiantes WHERE cc= '{$this->cc}'";
$this->con->query($sql);
}
public function ver(){
$sql = "SELECT * FROM estudiantes WHERE id = '{$this->id}' LIMIT 1";
$resultado = $this->con->consultaRetorno($sql);
$row = mysql_fetch_assoc($resultado);
//Set
$this->id = $row['id'];
$this->cedula = $row['cedula'];
$this->nombre = $row['nombre'];
$this->apellido = $row['apellido'];
$this->telefono = $row['telefono'];
$this->edad = $row['edad'];
$this->promedio = $row['promedio'];
$this->fecha = $row['fecha'];
return $row;
}
public function editar(){
$sql = "UPDATE estudiantes SET nombre = '{$this->nombre}', apellido = '{$this->apellido}',
telefono = '{$this->telefono}', edad = '{$this->edad}' WHERE id = '{$this->id}'";
$this->con->consultaSimple($sql);
}
}
?>
viewEmpleado.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
<?php
require_once('controllerEmpleado.php');
$contr = new controllerEmpleado();
$r = $contr->crear($_POST['cc'], $_POST['nombre'],
$_POST['correo'], $_POST['fecha_nac'], $_POST['sexo'],
$_POST['area_trab'], $_POST['cargo'], $_POST['fecha_ingr']);
if($r){
echo "Se ha registrado un nuevo estudiante";
}else{
echo "La cedula que esta intentando ingresar ya existe";
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Empleados</title>
</head>
<body>
<h1>Datos del Empleado</h1>
<form class="" action="" method="post">
<fieldset>
<label for="cc">Cedula <input type="text" name="cc" ></label><br><br>
<label for="nombre">Nombre <input type="text" name="nombre" value=""></label><br><br>
<label for="correo">Correro <input type="text" name="correo" value=""></label>
<label for="fecha_nac">Fecha de Nacimiento <input type="text" name="fecha_nac" value=""></label><br><br>
<label for="sexo">Sexo <input type="text" name="sexo" value=""></label>
<label for="area_trab"> Area de Trabajo <input type="text" name="area_trab" value=""></label><br><br>
<label for="cargo">Cargo <input type="text" name="cargo" value=""></label>
<label for="fecha_ingr">Fecha de ingreso <input type="text" name="fecha_ingr" value=""></label><br><br><br>
<input type="submit" name="enviar" value="crear">
</fieldset>
</form>
</body>
</html>
Valora esta pregunta
0