php注冊提交數(shù)據(jù)庫中 phpstudy建立數(shù)據(jù)庫

PHP網(wǎng)頁制作,怎樣把注冊表單的數(shù)據(jù)導(dǎo)入MySQL數(shù)據(jù)庫?

首先你要建立一個(gè)表,例如是注冊的用戶表user

創(chuàng)新互聯(lián)公司專業(yè)為企業(yè)提供吳興網(wǎng)站建設(shè)、吳興做網(wǎng)站、吳興網(wǎng)站設(shè)計(jì)、吳興網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計(jì)與制作、吳興企業(yè)網(wǎng)站模板建站服務(wù),十載吳興做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。

,里面的結(jié)構(gòu)有字段

id,

name,nickname,email等。

然后在你的表單處form

action="a.php"

method="post"

name="regform"(如果有圖片上傳,還要加上enctype="multipart/form-data")

,那么點(diǎn)擊表單提交按紐后,此表單將會(huì)交給處理頁a.php來作處理。

如果簡單點(diǎn),你就直接可以將表單傳遞過來的數(shù)據(jù)$_POST,直接用sql插入語句,insert

into來插入到數(shù)據(jù)庫,表user中。例如insert

into

user

set

name='".$_POST['name']."'.............................

php 實(shí)現(xiàn)簡單的注冊頁面 并把注冊信息插入到 mysql 數(shù)據(jù)庫中

注冊頁面: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 "注冊成功";

%

php,把注冊代碼輸入到數(shù)據(jù)庫中

建立index.php

輸入:

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對(duì)應(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 '注冊失敗';

}

?

php注冊信息提取,怎樣把注冊的信息放到數(shù)據(jù)庫內(nèi)?

傳統(tǒng)方法是用 form標(biāo)簽 將輸入的數(shù)據(jù) 提交到后臺(tái)的php, 由php獲得數(shù)據(jù)后寫入數(shù)據(jù)庫, 下面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ù)庫, 要看用什么數(shù)據(jù)庫了 要配置數(shù)據(jù)庫不是一兩句能說清的了//大致流程 是配置數(shù)據(jù)庫 打開數(shù)據(jù)連接 根據(jù)變量生成SQL語句 執(zhí)行語句?

如何在PHP里 進(jìn)入注冊頁面后打上資料點(diǎn)提交然后數(shù)據(jù)填入數(shù)據(jù)庫里 等于注冊了一個(gè)賬號(hào)

以下是簡單示例:

html

head

title注冊示例/title

/head

body

form method='post' action='test.php'

table bgcolor='#cccccc'

tr

tdEmail address:/td

tdinput type='text' name='email' size=30 maxlength=100/td/tr

tr

tdPreferred username br /(max 16 chars):/td

td valign='top'input type='text' name='username'

size=16 maxlength=16/td/tr

tr

tdPassword br /(between 6 and 16 chars):/td

td valign='top'input type='password' name='passwd'

size=16 maxlength=16/td/tr

tr

tdConfirm password:/td

tdinput type='password' name='passwd2' size=16 maxlength=16/td/tr

tr

td colspan=2 align='center'

input type='submit' value='Register'/td/tr

/table/form

?php

//連接數(shù)據(jù)庫

function db_connect()

{

$result = new mysqli('localhost', 'test', 'password', 'test');

if (!$result)

return false;

return $result;

}

//注冊用戶資料到數(shù)據(jù)庫

function register($username, $email, $password)

{

// connect to db

$conn = db_connect();

//檢查用戶名是否唯一

$result = $conn-query("select * from user where username='$username'");

if (!$result)

throw new Exception('無法搜索數(shù)據(jù)庫');

if ($result-num_rows0)

throw new Exception('該用戶名已經(jīng)存在,請檢查后重試!');

// 如果通過,則寫入數(shù)據(jù)庫

$result = $conn-query("insert into user values

('$username', sha1('$password'), '$email')");

if (!$result)

throw new Exception('無法寫入數(shù)據(jù)庫,請稍候重試');

return true;

}

$email=$_POST['email'];

$username=$_POST['username'];

$passwd=$_POST['passwd'];

$passwd2=$_POST['passwd2'];

register($username, $email, $passwd);

?

/body

/html

用php協(xié)注冊頁面,為實(shí)現(xiàn)在點(diǎn)擊注冊時(shí)將填寫數(shù)據(jù)導(dǎo)入我建的數(shù)據(jù)庫中,下面是我的代碼,怎么修改?

首先用戶名和密碼表單傳過來的值你能獲得到嗎? echo 值;exit;看能不能打印出來正常的值。如果值都沒有問題,都能打印出來。那么就連接數(shù)據(jù)庫,inseter into 表(字段名) values (對(duì)應(yīng)的字段值)。執(zhí)行sql語句就可以插入成功了。 首先你得知道是插入數(shù)據(jù)庫的問題在那里。

當(dāng)前名稱:php注冊提交數(shù)據(jù)庫中 phpstudy建立數(shù)據(jù)庫
當(dāng)前URL:http://muchs.cn/article14/dosssge.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供做網(wǎng)站、自適應(yīng)網(wǎng)站、電子商務(wù)標(biāo)簽優(yōu)化、定制開發(fā)云服務(wù)器

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

小程序開發(fā)