求一個微小的例子,能打通數(shù)據(jù)即可
Yii2 的表單如何提交數(shù)據(jù)到Mysql的?
dingmm2ff2
2017-05-27 11:00:46
TA貢獻81條經(jīng)驗 獲得超102個贊
用mvc模式,模型需要建立表單模型和數(shù)據(jù)模型,控制器中新建表單模型并且渲染視圖表單,表單模型中新建數(shù)據(jù)模型,并用save()方法保存,當(dāng)然你在conf中就需要配置連接數(shù)據(jù)庫,話說你yii2框架難道剛學(xué)嗎
TA貢獻150條經(jīng)驗 獲得超35個贊
form.html <form?action='php.php'?method='post'> ????<input?type='text'?name='text'?/> ????<input?type='submit'?name='submit'?value='submit'?/> </from> connect.php $connect=new?mysqli('localhost','root','','msg');//localhost基本不變的?root用戶名?‘’密碼有就寫?沒有空?msg你要連接的數(shù)據(jù)庫的名字 if?($connect->connect_error){ ????printf?(?"Connect?failed:?%s\n"?,??$connect?->?connect_error?); ????exit(); }else{ ????$connect->query("set?names?utf8");//設(shè)置數(shù)據(jù)庫的編碼為utf8 ????header("content-type:text/html;charset=utf8"); } php.php $text=$_POST['text']; 剩下的自己寫sql語句寫入數(shù)據(jù)庫
舉報