Home > Software engineering >  CodeIgniter: "404 Page Not Found The page you requested was not found" despite setting up
CodeIgniter: "404 Page Not Found The page you requested was not found" despite setting up

Time:06-22

I keep getting "404 Page Not Found The page you requested was not found.", despite setting up routes.php properly and also having a .htaccess. I've tried looking up solutions to this problem in this website but it doesn't help me as the solutions looks like something I did but nothing changes, or I couldn't understand what people said.

routes.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$route['default_controller'] = 'Crud';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;

Crud.php

<?php 
defined('BASEPATH') OR exit('No direct script access allowed');
class Crud extends CI_Controller 
{
    public function __construct()
    {
    /*call CodeIgniter's default Constructor*/
    parent::__construct();
    
    /*load database libray manually*/
    $this->load->database();
    
    /*load Model*/
    $this->load->model('Crud_model');
    }
        /*Insert*/
    public function savedata()
    {
        /*load registration view form*/
        $this->load->view('insert');
    
        /*Check submit button */
        if($this->input->post('save'))
        {
            $data['first_name']=$this->input->post('first_name');
            $data['middle_name']=$this->input->post('middle_name');
            $data['last_name']=$this->input->post('last_name');
            $data['username']=$this->input->post('username');
            $data['password']=$this->input->post('password');
            $data['confirmpassword']=$this->input->post('confirmpassword');
            $data['birthday']=$this->input->post('birthday');
            $data['email']=$this->input->post('email');
            $data['contactnumber']=$this->input->post('contactnumber');
            $response=$this->Crud_model->saverecords($data);
            if($response==true){
                    echo "Records Saved Successfully";
            }
            else{
                    echo "Insert error !";
            }
        }
    }
    
}
?>

Crud_model.php

<?php
class Crud_model extends CI_Model 
{
    
    function saverecords($data)
    {
        $this->db->insert('TSA2exam',$data);
        return true;
    }
    
}

insert.php

<!DOCTYPE html>  
<html>
<head>
<title>Registration form</title>
</head>
 
<body>
    <form method="post" action="<?= base_url() ?>Crud/savedata">
        <table width="600" border="1" cellspacing="5" cellpadding="5">
  <tr>
    <td width="230">First Name </td>
    <td width="329"><input type="text" name="first_name"/></td>
  </tr>
  <tr>
    <td>Middle Name </td>
    <td><input type="text" name="middle_name"/></td>
  </tr>
  <tr>
    <td>Last Name </td>
    <td><input type="text" name="last_name"/></td>
  </tr>
  <tr>
    <td>Username </td>
    <td><input type="text" name="username"/></td>
  </tr>
  <tr>
    <td>Password </td>
    <td><input type="text" name="password"/></td>
  </tr>
  <tr>
    <td>Confirm Password </td>
    <td><input type="text" name="confirmpassword"/></td>
  </tr>
  <tr>
    <td>Birthday </td>
    <td><input type="text" name="birthday"/></td>
  </tr>
  <tr>
    <td>Email ID </td>
    <td><input type="email" name="email"/></td>
  </tr>
  <tr>
    <td>Contact Number </td>
    <td><input type="email" name="email"/></td>
  </tr>
  <tr>
    <td colspan="2" align="center"><input type="submit" name="save" value="Save Data"/></td>
  </tr>
</table>
 
    </form>
</body>
</html>

database.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$active_group = 'default';
$query_builder = TRUE;

$db['default'] = array(
    'dsn'   => '',
    'hostname' => 'localhost',
    'username' => 'root',
    'password' => '',
    'database' => 'tsa2',
    'dbdriver' => 'mysqli',
    'dbprefix' => '',
    'pconnect' => FALSE,
    'db_debug' => (ENVIRONMENT !== 'production'),
    'cache_on' => FALSE,
    'cachedir' => '',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',
    'swap_pre' => '',
    'encrypt' => FALSE,
    'compress' => FALSE,
    'stricton' => FALSE,
    'failover' => array(),
    'save_queries' => TRUE
);

config.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$config['base_url'] = '';
$config['index_page'] = 'index.php';
$config['uri_protocol'] = 'REQUEST_URI';
$config['url_suffix'] = '';
$config['language'] = 'english';
$config['charset'] = 'UTF-8';
$config['enable_hooks'] = FALSE;
$config['subclass_prefix'] = 'MY_';
$config['composer_autoload'] = FALSE;
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';
$config['enable_query_strings'] = FALSE;
$config['controller_trigger'] = 'c';
$config['function_trigger'] = 'm';
$config['directory_trigger'] = 'd';
$config['allow_get_array'] = TRUE;
$config['log_threshold'] = 0;
$config['log_path'] = '';
$config['log_file_extension'] = '';
$config['log_file_permissions'] = 0644;
$config['log_date_format'] = 'Y-m-d H:i:s';
$config['error_views_path'] = '';
$config['cache_path'] = '';
$config['encryption_key'] = '';
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_samesite'] = 'Lax';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = NULL;
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
$config['cookie_prefix']    = '';
$config['cookie_domain']    = '';
$config['cookie_path']      = '/';
$config['cookie_secure']    = FALSE;
$config['cookie_httponly']  = FALSE;
$config['cookie_samesite']  = 'Lax';
$config['standardize_newlines'] = FALSE;
$config['global_xss_filtering'] = FALSE;
$config['csrf_protection'] = FALSE;
$config['csrf_token_name'] = 'csrf_test_name';
$config['csrf_cookie_name'] = 'csrf_cookie_name';
$config['csrf_expire'] = 7200;
$config['csrf_regenerate'] = TRUE;
$config['csrf_exclude_uris'] = array();
$config['compress_output'] = FALSE;
$config['time_reference'] = 'local';
$config['rewrite_short_tags'] = FALSE;
$config['proxy_ips'] = '';

CodePudding user response:

The route listed doesn't match a method in the Crud class. Without a method listed, $route['default_controller'] = 'crud'; is the same as $route['default_controller'] = 'crud/index';

So, You either need to create an index method in the Crud class. ie function index(){

Or change the route to :

$route['default_controller'] = 'crud/savedata';

If savedata is what you are trying to access.

CodePudding user response:

I think you need to add index.php here (index.php/Crud/savedata">

  • Related