CodeIgniter PHP 404 not found

1

I have created a PHP record, to save the data of an HTML form, in a database. When I hit the save button I get "The page you requested was not found", I have no idea why.

class Home extends CI_Controller {


public function index() 
{
    // Loading the model where the queries are executed
    $this->load->model('accounts');
    $this->load->library('javascript');



    $Cuentas = $this->accounts->getAllAccountInfo();

/*
    echo "<pre>";
    print_r($cuentas);
    echo "</pre>";
    die();
*/      
    $data =  array('Cuentas' => $Cuentas);
    $this->load->view('admin/index', $data);

}
public function demo()
{
    echo "Hola soy German";
}
}

// Model

<?php

class Accounts extends CI_Model {

    //$table_name = 'accounts'; // Main table name where the queries going to run

    public function __construct()
    {
            // Call the CI_Model constructor
            parent::__construct();


    }


    /**
     * This method returns the account information from all users on the database
     * @return Array()
     */
    public function getAllAccountInfo() {
        $query = $this->db->select('cuenta, nombre, buscar, pago, monto, fecha, banco, interes, concepto, cuota, credito, debito')->get('accounts')->result_array();
        return $query;
    }

}
    ?>

Here is the Controller and the model.

<html>
<head>
    <title>Cuentas por Cobrar</title>
    <link rel="stylesheet" type="text/css" href="<?php echo site_url('assets/css/bootstrap.css');?>" >
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
  <script type="text/javascript" src="<?php echo site_url('assets/js/bootstrap.js');?>"></script>

      <script src="http://s.codepen.io/assets/libs/modernizr.js" type="text/javascript"></script>
<link rel='stylesheet prefetch' href='http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css'>
<link rel='stylesheet prefetch' href='http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css'>
<link rel='stylesheet prefetch' href='http://cdnjs.cloudflare.com/ajax/libs/jquery.bootstrapvalidator/0.5.0/css/bootstrapValidator.min.css'>


    <style type="text/css">
        #success_message{ display: none;}
    </style>
</head>
<body>
        <div class="container">
    <form class="well form-horizontal" action="registro.php " method="POST"  id="contact_form">
<fieldset>

<!-- Form Name -->
<legend>Cuentas por Pagar</legend>

<!-- Text input-->

<div class="form-group">
  <label class="col-md-4 control-label">Cuenta</label>  
  <div class="col-md-4 inputGroupContainer">
  <div class="input-group">
  <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
  <input  name="first_name" placeholder="Número de Cuenta" class="form-control"  type="text">
    </div>
  </div>
</div>

<div class="form-group">
  <label class="col-md-4 control-label">Nombres</label>  
  <div class="col-md-4 inputGroupContainer">
  <div class="input-group">
  <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
  <input  name="first_name" placeholder="Nombre" class="form-control"  type="text">
    </div>
  </div>
</div>

<!-- Text input-->

<!-- Text input-->
       <div class="form-group">
  <label class="col-md-4 control-label">Fecha</label>  
    <div class="col-md-4 inputGroupContainer">
    <div class="input-group">
        <span class="input-group-addon"><i class="glyphicon glyphicon-time"></i></span>
  <input name="email" placeholder="Fecha" class="form-control"  type="text">
    </div>
  </div>
</div>


<!-- Text input-->

<div class="form-group">
  <label class="col-md-4 control-label">Banco</label>  
    <div class="col-md-4 inputGroupContainer">
    <div class="input-group">
        <span class="input-group-addon"><i class="glyphicon glyphicon-usd"></i></span>
  <input name="phone" placeholder="Banco" class="form-control" type="text">
    </div>
  </div>
</div>

<!-- Text input-->

<div class="form-group">
  <label class="col-md-4 control-label">Monto</label>  
    <div class="col-md-4 inputGroupContainer">
    <div class="input-group">
        <span class="input-group-addon"><i class="glyphicon glyphicon-usd"></i></span>
  <input name="address" placeholder="Monto" class="form-control" type="text">
    </div>
  </div>
</div>

<!-- Text input-->

<div class="form-group">
  <label class="col-md-4 control-label">Cuota</label>  
    <div class="col-md-4 inputGroupContainer">
    <div class="input-group">
        <span class="input-group-addon"><i class="glyphicon glyphicon-home"></i></span>
  <input name="city" placeholder="Cuota" class="form-control"  type="text">
    </div>
  </div>
</div>

<!-- Select Basic -->

<div class="form-group"> 
  <label class="col-md-4 control-label">Pago</label>
    <div class="col-md-4 selectContainer">
    <div class="input-group">
        <span class="input-group-addon"><i class="glyphicon glyphicon-list"></i></span>
    <select name="Pago" class="form-control selectpicker" >
      <option value=" " >Seleccionar Tipo de Pago</option>
      <option>Efectivo</option>
      <option>Tarjeta de Crédito</option>
      <option >Tarjeta de Débito</option>
      <option >Cheque</option>

    </select>
  </div>
</div>
</div>

<!-- Text input-->

<div class="form-group">
  <label class="col-md-4 control-label">Interés</label>  
    <div class="col-md-4 inputGroupContainer">
    <div class="input-group">
        <span class="input-group-addon"><i class="glyphicon glyphicon-usd"></i></span>
  <input name="zip" placeholder="Interés" class="form-control"  type="text">
    </div>
</div>
</div>

<!-- Text input-->

<!-- radio checks -->

<!-- Text area -->

<div class="form-group">
  <label class="col-md-4 control-label">Comentario</label>
    <div class="col-md-4 inputGroupContainer">
    <div class="input-group">
        <span class="input-group-addon"><i class="glyphicon glyphicon-pencil"></i></span>
            <textarea class="form-control" name="comment" placeholder="Comentario"></textarea>
  </div>
  </div>
</div>

<!-- Success message -->
<div class="alert alert-success" role="alert" id="success_message">Success <i class="glyphicon glyphicon-thumbs-up"></i> Thanks for contacting us, we will get back to you shortly.</div>

<!-- Button -->
<div class="form-group">
  <label class="col-md-4 control-label"></label>
  <div class="col-md-4">
    <button type="submit" class="btn btn-warning" >Guardar<span class="glyphicon glyphicon-send"></span></button>
  </div>
</div>

</fieldset>
</form>
</div>
    </div><!-- /.container -->
  <div class="container">
        <table class="table table-reverse">
            <thead>
                <tr>
                    <td>Cuenta</td>
                    <td>Nombres</td>
          <td>Monto</td>
          <td>Fecha</td>
                    <td>Pago</td>
                    <td>Banco</td>
          <td>Cuota</td>
          <td>Interés</td>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($Cuentas as $c): ?>
                    <tr>
                        <td><?php echo $c['cuenta'];?></td>
                        <td><?php echo $c['nombre'];?></td>
                        <td><?php echo $c['monto'];?></td>
            <td><?php echo $c['fecha'];?></td>
             <td><?php echo $c['pago'];?></td>
              <td><?php echo $c['banco'];?></td>
               <td><?php echo $c['cuota'];?></td>
                <td><?php echo $c['interes'];?></td>


                    </tr>
                <?php endforeach; ?>
            </tbody>
        </table>


    </div>

      <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js'></script>
<script type="text/javascript">
  $(document).ready(function() {
    $('#contact_form').bootstrapValidator({
        // To use feedback icons, ensure that you use Bootstrap v3.1.0 or later
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            first_name: {
                validators: {
                        stringLength: {
                        min: 2,
                    },
                        notEmpty: {
                        message: 'Por favor pon tu nombre'
                    }
                }
            },
             last_name: {
                validators: {
                     stringLength: {
                        min: 2,
                    },
                    notEmpty: {
                        message: 'Por favor pon tu apellido'
                    }
                }
            },
            email: {
                validators: {
                    notEmpty: {

                    },
                    emailAddress: {

                    }
                }
            },
            phone: {
                validators: {
                    notEmpty: {
                        message: 'Por favor ponga el nombre del banco'
                    },
                    phone: {


                    }
                }
            },
            address: {
                validators: {
                     stringLength: {
                        min: 8,
                    },
                    notEmpty: {
                        message: 'Inserte un Concepto'
                    }
                }
            },
            city: {
                validators: {
                     stringLength: {
                        min: 4,
                    },
                    notEmpty: {
                        message: 'Please supply your city'
                    }
                }
            },
            state: {
                validators: {
                    notEmpty: {
                        message: 'Ponga el valor de la cuota'
                    }
                }
            },
            zip: {
                validators: {
                    notEmpty: {
                        message: 'Ponga el valor del interés'
                    },
                    zipCode: {

                    }
                }
            },
            comment: {
                validators: {
                      stringLength: {
                        min: 10,
                        max: 200,
                        message:'Por favor ponga un comentario entre 10 y 200 caracteres'
                    },
                    notEmpty: {

                    }
                    }
                }
            }
        })
        .on('success.form.bv', function(e) {
            $('#success_message').slideDown({ opacity: "show" }, "slow") // Do something ...
                $('#contact_form').data('bootstrapValidator').resetForm();

            // Prevent form submission
            e.preventDefault();

            // Get the form instance
            var $form = $(e.target);

            // Get the BootstrapValidator instance
            var bv = $form.data('bootstrapValidator');

            // Use Ajax to submit form data
            $.post($form.attr('action'), $form.serialize(), function(result) {
                console.log(result);
            }, 'json');
        });
});
</script>

</body>
</html>
    
asked by José Quezada 02.08.2016 в 23:38
source

1 answer

0

The problem is that in your form you are not calling the controller method correctly, you are calling a registry.php file that is not known where it is located, besides you do not have any method to save in the database in your controller Home nor in your Model Accounts, you only have one method to obtain the records of the database.

If you want to save the form data you can do something like this:

Driver

class Home extends CI_Controller {

  function __construct(){
        parent::__construct();

    $this->load->model('Accounts');
  }

  public function guardarDatos()
  {
    //recoger datos del formulario
    /*Ejemplo para recoger datos del formulario. 
    Ya que estas enviando datos por post, para recojer los datos del mismo se hace de la siguiente manera.
    */

    $first_name = $this->input->post('first_name');  //donde el parametro que envias a la funcion post es el name del input en tu form. Y de la misma manera tienes que hacer con los inputs restantes.

    //llamar método del modelo para guardar datos
    $arreglo_datos = array('first_name'=>$firs_name);
    $this->accounts->saveData($arreglo_datos);
  }

}

Model

class Accounts extends CI_Model {

    public function __construct()
    {
            // Call the CI_Model constructor
            parent::__construct();
            $this->load->database();
    }

    public function saveData($arreglo_de_datos_formulario)
    {
      if(!$this->db->insert("accounts",$arreglo_de_datos_formulario)){
       return $this->db->error();
      }

    }


}

And in the action of your form you should put the call to the controller method in the following way

<form class="well form-horizontal" action="<?php echo site_url();?>/Home/guardarDatos" method="POST"  id="contact_form">

I recommend you read the official documentation so that you understand how the drivers and models work, besides there are complete examples of how to work with them.

Official Documentation

    
answered by 03.08.2016 / 00:11
source