drmg17928 2014-01-31 20:19
浏览 28
已采纳

CodeIgniter没有向数据库提交表单值

Setting the "method" attribute of form fixed this for me, everything is submitting to the database fine, now, I have a similar problem with my validating credentials but maybe it has the same root as this problem since I forgot about method in the first place, thank you all very much.

I have a problem while attempting to learn CodeIgniter and general MVC principles.

I have a sign up form view

<div class="container">
<form class="form-horizontal" style="width:500px;" action="sign_up">
<fieldset>

<!-- Form Name -->
<legend>Sign Up</legend>

<!-- Text input-->
<div class="control-group">
  <label class="control-label" for="username">Username</label>
  <div class="controls">
    <input id="username" name="username" placeholder="Username" class="input-xlarge" required="" type="text">
    <p class="help-block">Your username</p>
  </div>
</div>

<!-- Text input-->
<div class="control-group">
  <label class="control-label" for="email_address">Email</label>
  <div class="controls">
    <input id="email_address" name="email_address" placeholder="Email address " class="input-xlarge" required="" type="text">
    <p class="help-block">Enter your email address</p>
  </div>
</div>

<!-- Text input-->
<div class="control-group">
  <label class="control-label" for="first_name">First Name</label>
  <div class="controls">
    <input id="first_name" name="first_name" placeholder="First name" class="input-xlarge" required="" type="text">
    <p class="help-block">Enter your first name</p>
  </div>
</div>

<!-- Text input-->
<div class="control-group">
  <label class="control-label" for="last_name">Last Name</label>
  <div class="controls">
    <input id="last_name" name="last_name" placeholder="Last name" class="input-xlarge" type="text">
    <p class="help-block">help</p>
  </div>
</div>

<!-- Password input-->
<div class="control-group">
  <label class="control-label" for="password">Password Input</label>
  <div class="controls">
    <input id="password" name="password" placeholder="Password" class="input-xlarge" required="" type="password">
    <p class="help-block">help</p>
  </div>
</div>

<div class="control-group">
  <label class="control-label" for="password">Password Confirmation</label>
  <div class="controls">
    <input id="password2" name="password2" placeholder="Password" class="input-xlarge" required="" type="password">
    <p class="help-block">help</p>
  </div>
</div>

<!-- Button -->
<div class="control-group">
  <label class="control-label" for="singlebutton"></label>
  <div class="controls">
    <button class="btn btn-success" onclick="submit" >Sign Up</button>
  </div>
</div>

</fieldset>
</form>
</div>

Which submits to (user/)sign_up

public function sign_up() {

     $this->load->model('login_model');
        if($query = $this->login_model->create_member()){
            $data['main_content'] = 'user_login_view';
            $this->load->view('template', $data);
            }

    }

And passes to the model function "create_member"

function create_member()
    {
        $newdata = array(
            'user_name' => $this->input->post('username'),
            'password' => md5($this->input->post('password')),
            'email' => $this->input->post('email_address'),
            'first_name' => $this->input->post('first_name'),
            'last_name' => $this->input->post('last_name') 
            );

        $insert = $this->db->insert('users', $newdata);
        return $insert;
    }

I believe I have the correct table set up and I am following the MVC principle.

id  int(11)         
user_name   varchar(25)         
password    varchar(32)         
email   varchar(50)         
first_name  varchar(32)         
last_name   varchar(32)

My problem is the password is the only value that is passing over into the database for the rest it simply submits 0, any suggestions or obvious mistakes to point out?

ID      user_name   password                        email first_name last_name
20      0       d41d8cd98f00b204e9800998ecf8427e    0   0   0

Thank you

  • 写回答

2条回答 默认 最新

  • dounaoji2054 2014-01-31 20:53
    关注

    I would suggest you change your form open tag to explicitly call the controller, and you need to include a method="post" attribute to get the form to post. E.g.

    <form class="form-horizontal" style="width:500px;" action="/user/sign_up" method="post">
    

    If you wanted to use CI's form helper, you could use the following:

    $attributes = array('class' => 'form-horizontal', 'style' => 'width:500px;');
    
    echo form_open('user/sign_up', $attributes);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题