建立index.php
我們提供的服務(wù)有:成都網(wǎng)站制作、做網(wǎng)站、微信公眾號開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、瓊中黎族ssl等。為上千家企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的瓊中黎族網(wǎng)站制作公司
輸入:
form action='reg.php' method='method'
用戶名:input type='text' name='uname' /br
密碼:input type='password' name='upassword' /br
input type='注冊' value='submit' /
/form
保存退出
在相同目錄下建立regist.php
輸入:
?php
$username=$_POST[uname]; //通過POST方法獲得提交數(shù)據(jù),uname對應(yīng)index.php中的uname;upassword一樣
$userpassword=$_POST[upassword];
mysql_connect('localhost','root','數(shù)據(jù)庫密碼); //鏈接數(shù)據(jù)庫
mysql_select_db('數(shù)據(jù)庫名'); //選擇數(shù)據(jù)庫
$sql = "insert into user(uname,upassword) values"('$username',$userpassword); //插入數(shù)據(jù)的SQL字符串
if(mysql_query($sql)){ //mysql_query($sql)執(zhí)行插入語句,if為判斷是否插入成功
}else{
echo '注冊失敗';
}
?
首先你要建立一個表,例如是注冊的用戶表user
,里面的結(jié)構(gòu)有字段
id,
name,nickname,email等。
然后在你的表單處form
action="a.php"
method="post"
name="regform"(如果有圖片上傳,還要加上enctype="multipart/form-data")
,那么點(diǎn)擊表單提交按紐后,此表單將會交給處理頁a.php來作處理。
如果簡單點(diǎn),你就直接可以將表單傳遞過來的數(shù)據(jù)$_POST,直接用sql插入語句,insert
into來插入到數(shù)據(jù)庫,表user中。例如insert
into
user
set
name='".$_POST['name']."'.............................
先會寫html的表單
然后會寫php接收表單。
然后會連接數(shù)據(jù)庫,查找數(shù)據(jù)庫對應(yīng)字段。
判斷下
匹配跳轉(zhuǎn)到相應(yīng)頁面,或者記錄session等。
注冊頁面: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="注冊"/td/tr
/table
/form
接收頁面: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 "注冊成功";
%
傳統(tǒng)方法是用 form標(biāo)簽 將輸入的數(shù)據(jù) 提交到后臺的php, 由php獲得數(shù)據(jù)后寫入數(shù)據(jù)庫, 下面SubMsg.php 就是用來處理的后臺
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
后臺 SubMsg.php
? if (!isset($jqshul)){ echo "機(jī)器數(shù)量不存在," return;} echo $jqshul;//這個變量就是從前臺接收的機(jī)器數(shù)量. 字段的name 是什么就寫什么// 如何寫入數(shù)據(jù)庫, 要看用什么數(shù)據(jù)庫了 要配置數(shù)據(jù)庫不是一兩句能說清的了//大致流程 是配置數(shù)據(jù)庫 打開數(shù)據(jù)連接 根據(jù)變量生成SQL語句 執(zhí)行語句?
文章標(biāo)題:php注冊對接數(shù)據(jù)庫,php和mysql實(shí)現(xiàn)注冊
文章轉(zhuǎn)載:http://muchs.cn/article22/hcggjc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信小程序、微信公眾號、營銷型網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計(jì)公司、網(wǎng)站內(nèi)鏈、網(wǎng)站設(shè)計(jì)公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)