PHP - Problema a la hora de crear una consulta ingresar

 
Vista:

Problema a la hora de crear una consulta ingresar

Publicado por Jose Antonio (1 intervención) el 08/10/2016 00:17:37
Estimados ,

Soy principiante en php , estoy creando una consulta que guarde los datos ingresador en MVC

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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# datosController.php
 
<?php
 
 
  class datosController extends Controller{
 
     public function __construct()
	{
		parent::__construct();
	}
 
  	public function index(){
  		$objDatos=$this->loadModel('datos');
  		$this->_view->lista=$objDatos->getDatos();
  		$this->_view->renderizar('index');
  	}
 
 
    public function registrar()
	{
		$userName = trim($_POST['userName']);
		$firstName = trim($_POST['firstName']);
		$lastName = trim($_POST['lastName']);
		$email = trim($_POST['email']);
		$pass = trim($_POST['pass']);
		$objDatos = $this->loadModel('datos');
		$objDatos->ingresar($userName, $firstName,$lastName,$email,$pass);
		//$this->redireccionar('datos/registrar');
	    $this->_view->renderizar('registrar');
    }
 
  }
 
?>
 
# datosModel
 
<?php
 
	class datosModel extends Model
	{
	public function __construct()
	{
		parent::__construct();
	}
 
		public function getDatos(){
			$sql="SELECT * FROM Users;";
			$result=$this->_db->query($sql) or die("Error en el query : $sql");
		    return $result;
		}
 
	  public function ingresar($userName, $firstName,$lastName,$email,$pass)
	{
		$sql = "INSERT INTO Users (userName,firstName,lastName,email,pass) VALUES($userName, $firstName,$lastName,$email,$pass));";
		//echo $sql;
		$result = $this->_db->query($sql) or die("Error en el query : $sql");
		return;
	}
 
	}
 
?>
 
# index.phtml
 
<!--PAGE CONTENT -->
        <div id="content">
 
            <div class="inner">
                <div class="row">
                    <div class="col-lg-12">
                        <h2> Data Tables </h2>
                    </div>
                </div>
 
                <hr />
 
 
                <div class="row">
                <div class="col-lg-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            DataTables Advanced Tables
                        </div>
                        <div class="panel-body">
                            <div class="table-responsive">
                                <table class="table table-striped table-bordered table-hover" id="dataTables-example">
                                    <thead>
                                        <tr>
                                            <th><?php echo _('Usuario')?></th>
                                            <th><?php echo _('Apellidos')?></th>
                                            <th><?php echo _('Nombres')?></th>
                                            <th><?php echo _('Correo')?></th>
                                            <th><?php echo _('ClaveUsuario')?></th>
                                            <th><?php echo _('Opciones')?></th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                    <?php
                                    	while ($reg = $this->lista->fetch_object()):?>
                                        <tr class="odd gradeX">
                                            <td><?php echo $reg->userName?></td>
                                            <td><?php echo $reg->lastName?></td>
                                            <td><?php echo $reg->firstName?></td>
                                            <td><?php echo $reg->email?></td>
                                            <td><?php echo $reg->pass?></td>
 
                                        </tr>
                                    <?php endwhile;?>
                                    </tbody>
                                </table>
 
                                  <td><a href="<?php echo BASE_URL?>datos/registrar/<?php echo $reg->userName?>" class="btn btn-primary active" id="signup" role="button"><?php echo _('Encuesta')?></a>
                            </div>
 
                        </div>
                    </div>
                </div>
            </div>
        </div>
       <!--END PAGE CONTENT -->

NOTA: Quiero darle clic en Encuesta y me pase al formulario registra.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
# registra.phtml
 
 
<div class="tab-content">
 
      <label>Radio MALO</label>
      <div class="form-group" id="signup">
       <form action="<?php echo BASE_URL?>datos/ingresar" method='post' class="form-signin">
      <div class="radio">
       <label><?php echo _('Usuario')?>
       <input type="radio" name="userName" id="userName" value="SANDRA"<?php echo $this->ingresar->userName?> checked="checked" />jquispe
       </label>
       </div>
       <div class="radio">
       <label><?php echo _('Nombres')?>
      <input type="radio" name="firstName" id="firstName" value="JOSE ANTONIO"<?php echo $this->ingresar->firstName?> />JOSE ANTONIO
        </label>
        </div>
       <div class="radio">
       <label><?php echo _('Apellidos')?>
       <input type="radio" name="lastName" id="lastName" value="QUISPE "<?php echo $this->ingresar->lastName?> />Quispe Peña
       </label>
        </div>
         <div class="radio">
       <label><?php echo _('Correo')?>
       <input type="radio" name="email" id="email" value="jose@gmail.com"<?php echo $this->ingresar->email?> />Quispe@gmail.com
       </label>
        </div>
        <div class="radio">
       <label><?php echo _('Password')?>
       <input type="radio" name="pass" id="pass" value="12345"<?php echo $this->registrar->pass?> />Quispe@gmail.com
       </label>
        </div>
        <button class="btn text-muted text-center btn-success" type="submit">Registrar</button>
       </div>
 
 
</div>

NOTA: Este ejercicio es con un checkbox multiplex ,Cuando le doy clic en el boton encuesta se sale este error:

Notice: Undefined index: userName in /var/www/html/Sesion04/controllers/datosController.php on line 20 Notice: Undefined index: firstName in /var/www/html/Sesion04/controllers/datosController.php on line 21 Notice: Undefined index: lastName in /var/www/html/Sesion04/controllers/datosController.php on line 22 Notice: Undefined index: email in /var/www/html/Sesion04/controllers/datosController.php on line 23 Notice: Undefined index: pass in /var/www/html/Sesion04/controllers/datosController.php on line 24 Error en el query : INSERT INTO Users (userName,firstName,lastName,email,pass) VALUES(, ,,,));

Quisiera su apoyo para resolver este problema.

Gracias
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