傳統(tǒng)方法是用 form標(biāo)簽 將輸入的數(shù)據(jù) 提交到后臺(tái)的php, 由php獲得數(shù)據(jù)后寫(xiě)入數(shù)據(jù)庫(kù), 下面SubMsg.php 就是用來(lái)處理的后臺(tái)
創(chuàng)新互聯(lián)建站專業(yè)為企業(yè)提供舟山網(wǎng)站建設(shè)、舟山做網(wǎng)站、舟山網(wǎng)站設(shè)計(jì)、舟山網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)與制作、舟山企業(yè)網(wǎng)站模板建站服務(wù),10年舟山做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。
form name="MsgForm" method="post" action="SubMsg.php" onsubmit="return CheckForm();"label for='jqshul'機(jī)器數(shù)量/labelinput name="jqshul" type="text" class="InputBorder" id="jqshul" size="66" input type="submit" name="Submit" value="預(yù)定" /form
后臺(tái) SubMsg.php
? if (!isset($jqshul)){ echo "機(jī)器數(shù)量不存在," return;} echo $jqshul;//這個(gè)變量就是從前臺(tái)接收的機(jī)器數(shù)量. 字段的name 是什么就寫(xiě)什么// 如何寫(xiě)入數(shù)據(jù)庫(kù), 要看用什么數(shù)據(jù)庫(kù)了 要配置數(shù)據(jù)庫(kù)不是一兩句能說(shuō)清的了//大致流程 是配置數(shù)據(jù)庫(kù) 打開(kāi)數(shù)據(jù)連接 根據(jù)變量生成SQL語(yǔ)句 執(zhí)行語(yǔ)句?
建立index.php
輸入:
form action='reg.php' method='method'
用戶名:input type='text' name='uname' /br
密碼:input type='password' name='upassword' /br
input type='注冊(cè)' value='submit' /
/form
保存退出
在相同目錄下建立regist.php
輸入:
?php
$username=$_POST[uname]; //通過(guò)POST方法獲得提交數(shù)據(jù),uname對(duì)應(yīng)index.php中的uname;upassword一樣
$userpassword=$_POST[upassword];
mysql_connect('localhost','root','數(shù)據(jù)庫(kù)密碼); //鏈接數(shù)據(jù)庫(kù)
mysql_select_db('數(shù)據(jù)庫(kù)名'); //選擇數(shù)據(jù)庫(kù)
$sql = "insert into user(uname,upassword) values"('$username',$userpassword); //插入數(shù)據(jù)的SQL字符串
if(mysql_query($sql)){ //mysql_query($sql)執(zhí)行插入語(yǔ)句,if為判斷是否插入成功
}else{
echo '注冊(cè)失敗';
}
?
連接:mysql_connect("主機(jī)","用戶","密碼");
mysql_select_db("數(shù)據(jù)庫(kù)名");
寫(xiě)入數(shù)據(jù):mysql_query("insert
into
表名
(字段1,字段2)
values
("數(shù)據(jù)1","數(shù)據(jù)2")");
肯定的啊。php是一步步執(zhí)行的,進(jìn)入此頁(yè)面之后,就一步步執(zhí)行。沒(méi)等到你判斷的時(shí)候,它已經(jīng)插入到數(shù)據(jù)庫(kù)了。
把你判斷的內(nèi)容放到最上面。
注冊(cè)頁(yè)面:reg.html
form action="reg.php" method="POST"
table
trtd用戶名:/tdtdinput type="username" size="20"/td/tr
trtd密碼:/tdtdinput type="userpass" size="20"/td/tr
trtd確認(rèn)密碼:/tdtdinput type="ruserpass" size="20"/td/tr
trtd郵箱:/tdtdinput type="email" size="50"/td/tr
trtd電話:/tdtdinput type="telphone" size="20"/td/tr
trtdinput type="Submit" value="注冊(cè)"/td/tr
/table
/form
接收頁(yè)面:reg.php
%php
$db = mysql_connect("localhost", "root", "12345");
mysql_select_db("dataname", $db);
mysql_query("insert into tablename(username, userpass, email, telphone) values('$_POST[username]', '$_POST[userpass]', '$_POST[email]', '$_POST[telphone]')");
echo "注冊(cè)成功";
%
網(wǎng)站名稱:php注冊(cè)輸入數(shù)據(jù)庫(kù) php登陸注冊(cè)數(shù)據(jù)庫(kù)
標(biāo)題來(lái)源:http://chinadenli.net/article32/hpepsc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)頁(yè)設(shè)計(jì)公司、移動(dòng)網(wǎng)站建設(shè)、網(wǎng)站建設(shè)、定制網(wǎng)站、靜態(tài)網(wǎng)站、做網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)