CodeIgniter Forums
how to get data from html page and insert into database? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: how to get data from html page and insert into database? (/showthread.php?tid=3573)



how to get data from html page and insert into database? - El Forum - 10-11-2007

[eluser]Unknown[/eluser]
I am fresh for php. would you please tell me how to get data from html page and insert into database. i found the CI user guide tell us how to render data, however, it does not tell us how to get data. please refer the following example:


<input id="username" name="username" type="text" />
<input id="pwd" name="pwd" type="text" />
<input id="Submit1" name="submit1" type="submit" value="submit" />


there are 3 input fields in the page. how i can get the data from "username" and "pwd" textbox in the controller when visitor clicks on "submit"? and how to insert them into database?
thanks in advance.


how to get data from html page and insert into database? - El Forum - 10-11-2007

[eluser]obiron2[/eluser]
OK,

A quick help because this is not a CI or PHP question, it is a basic question about how the HTTP works with CGI (common gateway interface)

when you create a form you normally POST it <form action="POST">...

This then creates an associative array called $_POST which you can then manipulate in your PHP application (or any other language).

With CI you would then build a SQL insert statement, connect to your database and execute the SQL using $updateresult = $this->db->query($SQL) or something similar.

You would need to test the $updateresult to ensure that the insert happened correctly and take the relevant action.

Although you will find lots of help on these pages, I would politely suggest that maybe you are not ready for CI just yet and need to take a few steps back and understand more about how HTTP, CGI and PHP work. The learning curve is steep but enjoyable and definately worth it.

Good luck and keep reading the boards

Obiron


how to get data from html page and insert into database? - El Forum - 10-11-2007

[eluser]ELRafael[/eluser]
Code:
$username = $this->input->post('username');
$pwd = $this->input->post('pwd');

//OR

$username = $_POST['username'];
$pwd = $_POST['pwd'];



how to get data from html page and insert into database? - El Forum - 10-12-2007

[eluser]Unknown[/eluser]
Thanks obiron2 and ELRafael. Thanks for your excelent answer. It give me great help.