有兩處錯(cuò)誤
成都創(chuàng)新互聯(lián)是一家以網(wǎng)站建設(shè)公司、網(wǎng)頁(yè)設(shè)計(jì)、品牌設(shè)計(jì)、軟件運(yùn)維、成都網(wǎng)站營(yíng)銷、小程序App開發(fā)等移動(dòng)開發(fā)為一體互聯(lián)網(wǎng)公司。已累計(jì)為三維植被網(wǎng)等眾行業(yè)中小客戶提供優(yōu)質(zhì)的互聯(lián)網(wǎng)建站和軟件開發(fā)服務(wù)。
$sql = "insert into users(user,pass) values('$user','$pass')";改為
$sql = "insert into users(user,pass) values(".$user.",".$pass.")";
$user??$pass? 沒有賦值操作,應(yīng)該是為空,給它賦值一下應(yīng)該就可以了
建立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]; //通過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è)失敗';
}
?
注冊(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è)成功";
%
傳統(tǒng)方法是用 form標(biāo)簽 將輸入的數(shù)據(jù) 提交到后臺(tái)的php, 由php獲得數(shù)據(jù)后寫入數(shù)據(jù)庫(kù), 下面SubMsg.php 就是用來處理的后臺(tái)
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 是什么就寫什么// 如何寫入數(shù)據(jù)庫(kù), 要看用什么數(shù)據(jù)庫(kù)了 要配置數(shù)據(jù)庫(kù)不是一兩句能說清的了//大致流程 是配置數(shù)據(jù)庫(kù) 打開數(shù)據(jù)連接 根據(jù)變量生成SQL語(yǔ)句 執(zhí)行語(yǔ)句?
首先你要建立一個(gè)表,例如是注冊(cè)的用戶表user
,里面的結(jié)構(gòu)有字段
id,
name,nickname,email等。
然后在你的表單處form
action="a.php"
method="post"
name="regform"(如果有圖片上傳,還要加上enctype="multipart/form-data")
,那么點(diǎn)擊表單提交按紐后,此表單將會(huì)交給處理頁(yè)a.php來作處理。
如果簡(jiǎn)單點(diǎn),你就直接可以將表單傳遞過來的數(shù)據(jù)$_POST,直接用sql插入語(yǔ)句,insert
into來插入到數(shù)據(jù)庫(kù),表user中。例如insert
into
user
set
name='".$_POST['name']."'.............................
往數(shù)據(jù)庫(kù)里插入數(shù)據(jù)不能用雙引號(hào)。改成這樣。
$query="insert into user(name,sex,psd,email,miv,mid) values(‘$name’,‘$sex’,‘$psd1’,‘$email’,‘$qst’,‘$as’)";
像這樣的問題,你直接echo一下 然后手動(dòng)插入數(shù)據(jù)庫(kù)就知道了。
文章標(biāo)題:php注冊(cè)信息寫入數(shù)據(jù)庫(kù) php實(shí)現(xiàn)用戶注冊(cè)
文章出自:http://chinadenli.net/article10/doohido.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)建站、App開發(fā)、定制網(wǎng)站、服務(wù)器托管、云服務(wù)器、靜態(tài)網(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í)需注明來源: 創(chuàng)新互聯(lián)