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
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;