Use Codeigniter with php, in a tutorial a crud is done, I already had the insert and I tried to adapt the code to make an update, but the code of the tutorial calls the model mod twice, and in one it happens only 1 argument. I think that's why it gives the error. What should I change in the code to make it work?
main_model
<?php
class Main_model extends CI_Model
{
public function __construct() {
//llamamos al constructor de la clase padre
parent::__construct();
//cargamos la base de datos
$this->load->database();
}
public function mod($DocIdent, $modificar="NULL", $Nombre, $Apellido, $Direccion, $Telefono, $Estado, $FechaIngreso, $Password){
if($modificar=="NULL"){
$consulta=$this->db->query("SELECT * FROM tbl_cliente WHERE DocIdent=$DocIdent");
return $consulta->result();
}else{
$consulta=$this->db->query("
UPDATE tbl_cliente SET Nombre='$Nombre', Apellido='$Apellido',
Direccion='$Direccion', Telefono='$Telefono', Estado='$Estado', FechaIngreso='$FechaIngreso', Password='$Password'
WHERE DocIdent=$DocIdent;
");
if($consulta==true){
return true;
}else{
return false;
}
}
}
client_search (the driver)
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class cliente_buscar extends CI_Controller{
function __construct(){
parent::__construct();
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->load->database();
//llamo o incluyo el modelo
$this->load->model('main_model');
}
//controlador para modificar al que
//le paso por la url un parametro
public function mod($DocIdent){
if(is_numeric($DocIdent)){
$datos["mod"]=$this->main_model->mod($DocIdent);
$this->load->view("modificar_view",$datos);
if($this->input->post("submit")){
$mod=$this->main_model->mod(
$DocIdent,
$this->input->post("submit"),
$this->input->post("Nombre"),
$this->input->post("Apellido"),
$this->input->post("Direccion"),
$this->input->post("Telefono"),
$this->input->post("Estado"),
$this->input->post("FechaIngreso"),
$this->input->post("Password")
);
if($mod==true){
//Sesion de una sola ejecución
$this->session->set_flashdata('correcto', 'Usuario modificado correctamente');
}else{
$this->session->set_flashdata('incorrecto', 'No se pudo modificar el registro');
}
redirect(base_url());
}
}else{
redirect(base_url());
}
}
client_search_ form
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<TITLE></TITLE>
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0">
<!-- <link rel="stylesheet" type="text/css" href="<?php /*echo base_url();*/ ?>/css/estilos.css">
<link rel="stylesheet" type="text/css" href="http://localhost/CesdeCodeIgniter/application/views/css/estilos.css"> -->
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>/css/bootstrap.min.css">
<style type="text/css">
body{
margin:0;
color:#6a6f8c;
font:600 16px/18px 'Open Sans',sans-serif;
}
html {
height: 100%;
}
</style>
</head>
<body>
<br>
<div class="container-fluid">
<br>
<div class="row">
<div class="col-md-10">
<ul class="nav nav-pills">
<li role="presentation" ><a href="http://localhost/CesdeCodeIgniter/index.php/cliente/mostrarInicio">Inicio</a></li>
<li role="presentation" class="active"><a href="http://localhost/CesdeCodeIgniter/index.php/cliente/mostrarDatos/cliente">Ingresar Cliente </a></li>
<li role="presentation" ><a href="http://localhost/CesdeCodeIgniter/index.php/cliente/buscarCliente">Buscar Cliente </a></li>
<li role="presentation"><a href="cuentaxcliente.php">Cuenta Cliente</a></li>
<li role="presentation"><a href="transaccuenta.php">Transación Cuenta</a></li>
<li role="presentation"><a href="http://localhost/CesdeCodeIgniter/index.php/transaccion/IngresarTransaccion">Ingresar Tipo de Transacción</a></li>
<li role="presentation"><a href="http://localhost/CesdeCodeIgniter/index.php/transaccion/BuscarTransaccion">Buscar Tipo de Transacción</a></li>
<li role="presentation"><a href="http://localhost/CesdeCodeIgniter/index.php/cliente/login">Login</a></li>
</ul>
</div>
</div>
</div>
<br><br>
<h2>Cliente</h2>
<?php
//Si existen las sesiones flasdata que se muestren
if($this->session->flashdata('correcto'))
echo $this->session->flashdata('correcto');
if($this->session->flashdata('incorrecto'))
echo $this->session->flashdata('incorrecto');
?>
<table border="1">
<?php
foreach($ver as $fila){
?>
<tr>
<td>
<?=$fila->DocIdent;?>
</td>
<td>
<?=$fila->Nombre;?>
</td>
<td>
<?=$fila->Apellido;?>
</td>
<td>
<?=$fila->Direccion;?>
</td>
<td>
<?=$fila->Telefono;?>
</td>
<td>
<?=$fila->Estado;?>
</td>
<td>
<?=$fila->FechaIngreso;?>
</td>
<td>
<?=$fila->Password;?>
</td>
<td>
<a href="<?=base_url("cliente_buscar/mod/$fila->DocIdent")?>">Modificar</a>
<a href="<?=base_url("cliente_buscar/eliminar/$fila->DocIdent")?>">Eliminar</a>
</td>
</tr>
<?php
}
?>
</table>
<br>
<script type="text/javascript" src="http://localhost/CesdeCodeIgniter/js/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="http://localhost/CesdeCodeIgniter/js/bootstrap.min.js"></script>
</body>
</html>
modify_view
<!DOCTYPE HTML>
<html lang="es">
<head>
<meta charset="UTF-8" />
<title>Modificar Cliente</title>
</head>
<body>
<h2>Modificar Cliente</h2>
<form action="" method="POST">
<?php foreach ($mod as $fila){ ?>
<input type="text" name="docIdent" value="<?=$fila->DocIdent?>"/>
<input type="text" name="nombre" value="<?=$fila->Nombre?>"/>
<input type="text" name="apellido" value="<?=$fila->Apellido?>"/>
<input type="text" name="direccion" value="<?=$fila->Direccion?>"/>
<input type="text" name="telefono" value="<?=$fila->Telefono?>"/>
<input type="text" name="estado" value="<?=$fila->Estado?>"/>
<input type="text" name="fechaIngreso" value="<?=$fila->FechaIngreso?>"/>
<input type="text" name="password" value="<?=$fila->Password?>"/>
<input type="submit" name="submit" value="Modificar"/>
<?php } ?>
</form>
<a href="<?=base_url()?>">Volver</a>
</body>
</html>