数据库问题

时间:2011-02-03 17:35:50

标签: jquery database codeigniter

我需要使用codeIgniter创建一个项目,我将数据发送到数据库时遇到问题。 我有一个小jQuery函数用于选择复选框,然后将复选框的id放到标签上。

但是当我想将它发送到数据库时,它总是返回O。

这是我的jquery函数:

 $("#seatDiv").html($(this).val());
 $(document).ready(function() {
     $("input[name=check]").change(function() {
        $("#seatDiv").html($(this).val());
     })
 });

这是ID出现的标签:

   <td><div id="seatDiv"> <?php echo form_label($zitplaats); ?> </div></td>

这是在我的用户控制器中:

    $username = $this->input->post ('reg_username');
    $email = $this->input->post ('reg_email');
    $gsmnummer = $this->input->post ('reg_gsmnummer');
    $zitplaats = $this->input->post ('reg_zitplaats');
    echo $username;
    echo $email;
    echo $gsmnummer;
    echo $zitplaats;

    $this->User_model->register_user($username, $email, $gsmnummer, $zitplaats);

这是我的user_model:

class User_model extends Model{
    function User_model() {
        parent :: Model() ;
    }
    function register_user($username, $email, $gsmnummer, $zitplaats){

        $query_str ="INSERT INTO tbl_reservering (username,gsmnummer,email,zitplaats)VALUES(?, ?, ?, ?)";
        $this->db->query($query_str,array($username,$email,$gsmnummer,$zitplaats));
    }
}

这是我的整个HTML代码,除了复选框表

 <body>
    <h1> reservering </h1>
    <p> vul in de onderste gegevens in. </p>
  <?php echo validation_errors() ?>
    <?php
        echo form_open('user/register');
        $username = array(
           'name'       =>  'reg_username',
            'id'        =>  'reg_username',
            'value'     =>  set_value('reg_username')
        );
           $email = array(
           'name'       =>  'reg_email',
            'id'        =>  'reg_email',
            'value'     =>  set_value('reg_email')
        );
            $gsmnummer = array(
           'name'       =>  'reg_gsmnummer',
            'id'        =>  'reg_gsmnummer',
            'value'     =>  set_value('reg_gsmnummer')
        );
            $zitplaats = array(
           'name'       =>  'reg_zitplaats',
            'id'        =>  'reg_zitplaats',
            'value'     =>  ''
        );
    ?>
    <table>
        <tr>
            <td><label> Naam </label></td>
           <td> <div> <?php echo form_input($username); ?></div></td>
       </tr>
        <tr>
            <td><label>e-mail </label></td>
            <td><div> <?php echo form_input($email); ?></div></td>
        </tr>
        <tr>
            <td><label> gsm-nummer </label></td>
            <td><div> <?php echo form_input ($gsmnummer); ?> </div></td>
        </tr>
        <tr>
            <td><label>zitplaats</label></td>

             <td><div id="seatDiv"> <?php echo form_label('seat'); ?> </div></td>
        </tr>
        <tr>
       <td> <?php echo form_submit(array('name'=> 'verzend','value' => 'verzend')); ?> </td>

      <?php echo form_close(); ?>

     <?php echo form_open('user/register2'); ?>
             <td><?php echo form_submit(array('name'=> 'Voeg_toe','value' => 'voeg toe'));  ?> </td>
       </tr>
    </table>

     <?php echo form_close(); ?>
 <table>

1 个答案:

答案 0 :(得分:0)

您的jQuery引用了div "seatDiv",而不是表单标签"zitplaats"的值。但是您要发布"zitplaats"的值。