简体   繁体   English

如何使用codeigniter编辑表单输入中的数据库数据

[英]how to edit data of database in form entry with 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. 我制作了一个表格,从用户那里购买数据来购买一本书,我使用了Codeigniter的表格验证,当数据遵循规则数据库接受数据并将其显示给用户时,在显示结果页面中,我将按钮放回到第一页并更改数据。

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? 我做了check_data_entry来检查数据验证,接受数据后用户可以看到结果页面我希望用户能够在第一页中从数据库中编辑数据,我将用户重定向到第一页但是我不知道如何在第一页中显示数据名称文本输入,set_value似乎应该有第二个数据,但是这次来自数据库,但是又如何呢? i don't know, i send an array from database to this page . 我不知道,我从数据库向此页面发送了一个数组。

please show me solution. 请告诉我解决方案。 thank you 谢谢

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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM