2018-06-05 12:39
浏览 130


I want to make a simple app using CodeIgniter, PHP, and MySQL which collects data using a form into MySQL database. The following are my codes - for the form1.php, I'm using -


    <div class="container">
    <div class="row">
    <div class="col-md-4 col-md-offset-4">
    <div class="login-panel panel panel-success">
    <div class="panel-heading">
        <h3 class="panel-title">Form</h3>
    <div class="panel-body">

    <form role="form" method="post" action="<?php echo base_url('/form/add_user'); ?>">
       <input class="form-control" placeholder="Name" type="text" name="name"><br>
       Age: <br>
       <input class="form-control" placeholder="Age" type="number" name="age"><br>
       <input type="radio" name="gender" value="male">Male<br>
       <input type="radio" name="gender" value="female">Female<br><br>
       <select name="state">
         <option value="maharashtra">Maharashtra</option>
         <option value="west bengal">West Bengal</option>
         <option value="kerela">Kerela</option>
         <option value="bihar">Bihar</option>
       <input class="btn btn-lg btn-success btn-block" type="submit" value="Submit" name="submit" >

For the controller -

class Form extends CI_Controller {

public function __construct(){


public function index()

public function add_user(){


    redirect ('form');

And the user model looks like -

class User_model extends CI_model{

public function add_user($user){
  $this->db->insert('user', $user);


Now I get my form when I put in the browser. I am using WAMP server and the name of my app is samplesurvey.
But when I submit, I get the error:

The requested URL /samplesurvey/form/add_user was not found on this server.

I have edited the .htaccess file and the Apache module as in other answers but it is not working.

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duanji8887 2018-06-05 13:16

    It is good practice to use site_url instead of base_url while defining action URL of a form.

    <form role="form" method="post" action="<?php echo site_url('form/add_user'); ?>">

    wrong .htaccess can be the issue, so temporarily remove the .htaccess file.

    Make sure in config.php

    $config['base_url'] = ''; 
    $config['index_page'] = 'index.php';

    It should work perfectly.

    打赏 评论

相关推荐 更多相似问题