Welcome Guest, Not a member yet? Register   Sign In
Inserting data from a form(what evrybody seems to have forgotten),help a newbie for a better today
#1

[eluser]phpserver[/eluser]
View:::

myform.php

Controller

<?

class Arc extends Controller {
//Validation function included
function insert_into_mysql()
{

//Help

}

}
?>

Model

<?

class Model extends Controller{

function insert()
{
//help
}

}

?>

I have spent a whole week trying to insert data from a form into mysql,i have failed terribly.
I am used to using '$_POST[email]' format when posting data and nothing so far works.
I want to insert email and username into a database from a form as you can gather from above.
Will somebody come to my resque,its friday goddamn it,it has been a long five days.
#2

[eluser]Colin Williams[/eluser]
Try harder. Read the User Guide. Extrapolate
#3

[eluser]new developer[/eluser]
Your model
Code:
function insert(){

$data = array('name' => $_POST['name'],
'email' => $_POST['email'],

);
$this-> db-> insert('your_table',$data);

}

your controller
Code:
function create(){
if ($this-> input-> post('name')){
$this-> YourModel-> insert();
$this-> session-> set_flashdata('message','Added to mysql');
redirect('welcome/index','refresh');
}else{
//$data Supply your data to the view
$this-> load-> vars($data);
$this-> load-> view('Your_view');
}
}
#4

[eluser]a&w[/eluser]
What @new developer posted seems to circumvent the form validation's sanitization, etc., just grabbing the raw post data.

You might want to check this thread: http://ellislab.com/forums/viewthread/97045/ (and follow your nose to the linked thread in #2 where this is discussed further).
#5

[eluser]Colin Williams[/eluser]
Any sanitation CI does happens directly on the $_POST super-global. But even so, the model shouldn't have to go sniff out data from the HTTP request. The controller should supply it.




Theme © iAndrew 2016 - Forum software by © MyBB