Welcome Guest, Not a member yet? Register   Sign In
[solved] Get data from MySQL in form, validate new values and update MySQL
#1

[eluser]Jan_1[/eluser]
So I've read and understand the User Guide 'Form Validation' and 'Database Class'.
I do get datas out of my database, but how do I have to handle it,
if I want to write old data into the form-fields and let them update by user?

Found lot's of hints, but don't get them together.
Is there any good manual, which I didn't found?
Thank you!
Jan
#2

[eluser]TheFuzzy0ne[/eluser]
You can give a default value as a second parameter to set_value(). If validation hasn't run, that default value will be shown.
#3

[eluser]pistolPete[/eluser]
Have a look at this thread: http://ellislab.com/forums/viewreply/533725/
#4

[eluser]Jan_1[/eluser]
Thank you, both. Incredible fast answers.
Second parameter in set_value() seemed to me as the faster way for the moment.

What about the Update-Statement. I have tryed with
Code:
$data = array(
               'title' => $title,
               'name' => $name,
               'date' => $date
            );

$this->db->where('id', $id);
$this->db->update('mytable', $data);
But I think I missunderstand basics and do it at the wrong place. It did'nt work.
#5

[eluser]pistolPete[/eluser]
Please be more precise, "It did’nt work." is not a good error description!
Did you get an error message?
Where do you put that code, where is that "wrong place" ?
#6

[eluser]Jan_1[/eluser]
So, this is how I've 'succesfully' done it:

I wrote 3 functions with sql-queries in my MODEL
Quote: a) select_data
b) update_data
c) delete_data

I've used 3 functions in my CONTROLLER to edit data from database.
Quote: 1. function get_data()
wich uses the model-function 'a' to bring data to a formular-VIEW
2. function edit_data()
which uses the model-function 'b' to update data in database. It ends with a redirect to controller-function 1 (get_data)
3. delete data()
which uses the model-function 'c' to delete data in database. It ends with a redirect to controller-function 1 (get_data)
If that works it might be useful to extend it with a second View (Do you really want to do this") or something similar.




Theme © iAndrew 2016 - Forum software by © MyBB