Show page code
<formAction= "/lyb/index.php/index/insert.html"Method= "POST"><inputname= "text"type= "text"value= "form Submission" /><inputname= "AAA"type= "Submit" /></form>
The action address should be replaced with the U method in thinkphp, that is, to find a method in the controller, this method is responsible for receiving post data, and add data to the database
Controller code
<?PHP//This class is automatically generated by the system and is intended for testing purposes onlyclassIndexactionextendsAction { Public functionindex () {$this-display (); } Public functionInsert () {Header("content-type:text/html; Charset=utf-8 ");$Text=$_post[' Text ']; $Dao= M ("Ly");//instantiating a model class $list=$Dao-Select (); //building an array of data to write $data["content"] =$Text;if($lastInsId=$Dao->add ($data)){ EchoThe Insert Data ID is:$lastInsId"; } Else { $this->error (' Data write Error! ‘); } Dump ($Text);$this->assign (' div ',$list); $this->display (' Index '); }}
Page display Code
<formAction= "{: U (' Index/insert ')}"Method= "POST"><inputname= "text"type= "text"value= "form Submission" /><inputname= "AAA"type= "Submit" /></form><foreachname= "Div"Item= "Vo"><Divstyle= "Background-color: #FF8F59; onclick="window.open ">{$vo. Content}</Div> </foreach>
Finally, the database design and the database Setup code
Database Setup Code
<?PHPreturn Array( //' Config item ' = ' config value '//' USERNAME ' + ' admin ',//assignment//database configuration information' Db_type ' = ' mysql ',//Database Type' db_host ' = ' localhost ',//Server Address' Db_name ' = ' lyb ',//Database name' Db_user ' = ' root ',//User name' Db_pwd ' = ' root ',//Password' Db_port ' = 3306,//Port' Db_prefix ' = ' xp_ ',//database table prefix//other project configuration Parameters//...);?>
Http://url.cn/dmfB8I
Thinkphp Message Board Skeleton