doubao7287 2016-06-03 14:09
浏览 24

如何使用codeigniter编辑表单条目中的数据库数据

i made a form to get data from user to buy a book i used form validation of Codeigniter, when data follow rules database accept data and show it to user, in show result page i put a button to back to first page and change data.

but i want first page show data from database not empty text input.

form with form validation: (it is only for first name)

<?php if($errors= validation_errors()):?>
                <div class="alert alert-danger">
                    <?php echo $errors; ?>
                </div>
            <?php endif;?>

        <form action="<?php echo base_url();?>my_site/check_data_entry"  method="post" >

        <div>
                <label>first name</label>
                <input type="text" name="txt_fname"  value="<?php echo set_value('txt_fname'); ?>" required>
                <?php echo form_error('txt_fname');?>
            </div>

i made check_data_entry to check data validation, after accept the data user can see result page i want user to be able to edit data from database in first page, i redirect user to first page but i don't know how to show data in first name text input, set_value seems should have second data but this time from database but how? i don't know, i send an array from database to this page .

please show me solution. thank you

  • 写回答

1条回答 默认 最新

  • douzhimei8259 2016-06-03 14:21
    关注

    When you say edit database, do you mean edit a row in the database that is already there or add a new row? The reason why I am asking is because you only have one field on your form, so you can't really use that data to edit a current row, but you can add a new row. Here are two lines of code that might get you on the right track:

    $FirstName = $this->input->post('txt_fname');
    
    INSERT INTO table_name ($FirstName) values (first_name_column_in_database);
    

    If you have any follow up questions, please feel free to ask.

    EDIT:

    Based off of your comment, you are wanting to edit a row in the database and you have other fields. I will just make up those other fields here since you did not give them:

    $FirstName   = $this->input->post('txt_fname');
    $PhoneNumber = $this->input->post('txt_phone');
    $Email       = $this->input->post('txt_email');
    
    UPDATE
      table_name
    SET
      phone_column_in_database = $PhoneNumber,
      email_column_in_database = $Email
    WHERE
      first_name_column_in_database = $FirstName;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?