頁(yè)面插入數(shù)據(jù)庫(kù)php php頁(yè)面添加信息到數(shù)據(jù)庫(kù)

php插入數(shù)據(jù)庫(kù):我建立個(gè)注冊(cè)頁(yè)面,但是不管我輸入什么。都會(huì)插入數(shù)據(jù)庫(kù)

肯定的啊。php是一步步執(zhí)行的,進(jìn)入此頁(yè)面之后,就一步步執(zhí)行。沒(méi)等到你判斷的時(shí)候,它已經(jīng)插入到數(shù)據(jù)庫(kù)了。

創(chuàng)新互聯(lián)建站專注于中大型企業(yè)的成都網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)和網(wǎng)站改版、網(wǎng)站營(yíng)銷服務(wù),追求商業(yè)策劃與數(shù)據(jù)分析、創(chuàng)意藝術(shù)與技術(shù)開(kāi)發(fā)的融合,累計(jì)客戶千余家,服務(wù)滿意度達(dá)97%。幫助廣大客戶順利對(duì)接上互聯(lián)網(wǎng)浪潮,準(zhǔn)確優(yōu)選出符合自己需要的互聯(lián)網(wǎng)運(yùn)用,我們將一直專注成都品牌網(wǎng)站建設(shè)和互聯(lián)網(wǎng)程序開(kāi)發(fā),在前進(jìn)的路上,與客戶一起成長(zhǎng)!

把你判斷的內(nèi)容放到最上面。

著急?。?!php 頁(yè)面內(nèi)容插入數(shù)據(jù)庫(kù)???同時(shí)頁(yè)面內(nèi)容顯示在另外頁(yè)面上?

你把插入數(shù)據(jù)和顯示放在同一個(gè)頁(yè)面..

例如.

index.php是顯示表單的頁(yè)面..

然后他的form的action參數(shù)是去第二個(gè)頁(yè)面input.php

然后就在input.php..執(zhí)行數(shù)據(jù)插入并且顯示內(nèi)容

index.php的內(nèi)容

input.php的內(nèi)容

$id

=

$_POST['id'];

/*

執(zhí)行數(shù)據(jù)插入的語(yǔ)句

*/

echo

$id;

PHP加數(shù)據(jù)庫(kù)

把來(lái)自表單的數(shù)據(jù)插入數(shù)據(jù)庫(kù)

現(xiàn)在,我們創(chuàng)建一個(gè) HTML 表單,這個(gè)表單可把新記錄插入 "Persons" 表。

這是這個(gè) HTML 表單:

1

2

3

4

5

6

7

8

9

10

11

12

html

body

form action="insert.php" method="post"

Firstname: input type="text" name="firstname" /

Lastname: input type="text" name="lastname" /

Age: input type="text" name="age" /

input type="submit" /

/form

/body

/html

當(dāng)用戶點(diǎn)擊上例中 HTML 表單中的提交按鈕時(shí),表單數(shù)據(jù)被發(fā)送到 "insert.php"。"insert.php" 文件連接數(shù)據(jù)庫(kù),并通過(guò) $_POST 變量從表單取回值。然后,mysql_query() 函數(shù)執(zhí)行 INSERT INTO 語(yǔ)句,一條新的記錄會(huì)添加到數(shù)據(jù)庫(kù)表中。

下面是 "insert.php" 頁(yè)面的代碼:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

?php

$con = mysql_connect("localhost","peter","abc123");

if (!$con)

{

die('Could not connect: ' . mysql_error());

}

mysql_select_db("my_db", $con);

$sql="INSERT INTO Persons (FirstName, LastName, Age)

VALUES

('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";

if (!mysql_query($sql,$con))

{

die('Error: ' . mysql_error());

}

echo "1 record added";

mysql_close($con)

?

PHP在網(wǎng)站上實(shí)現(xiàn)跟數(shù)據(jù)庫(kù)添加數(shù)據(jù)

把來(lái)自表單的數(shù)據(jù)插入數(shù)據(jù)庫(kù)

現(xiàn)在,我們創(chuàng)建一個(gè) HTML 表單,這個(gè)表單可把新記錄插入 "Persons" 表。

這是這個(gè) HTML 表單:

html

body

form?action="insert.php"?method="post"

Firstname:?input?type="text"?name="firstname"?/

Lastname:?input?type="text"?name="lastname"?/

Age:?input?type="text"?name="age"?/

input?type="submit"?/

/form

/body

/html

當(dāng)用戶點(diǎn)擊上例中 HTML 表單中的提交按鈕時(shí),表單數(shù)據(jù)被發(fā)送到 "insert.php"。"insert.php" 文件連接數(shù)據(jù)庫(kù),并通過(guò) $_POST 變量從表單取回值。然后,mysql_query() 函數(shù)執(zhí)行 INSERT INTO 語(yǔ)句,一條新的記錄會(huì)添加到數(shù)據(jù)庫(kù)表中。

下面是 "insert.php" 頁(yè)面的代碼:

?php

$con?=?mysql_connect("localhost","peter","abc123");

if?(!$con)

{

die('Could?not?connect:?'?.?mysql_error());

}

mysql_select_db("my_db",?$con);

$sql="INSERT?INTO?Persons?(FirstName,?LastName,?Age)

VALUES

('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";

if?(!mysql_query($sql,$con))

{

die('Error:?'?.?mysql_error());

}

echo?"1?record?added";

mysql_close($con)

?

本文名稱:頁(yè)面插入數(shù)據(jù)庫(kù)php php頁(yè)面添加信息到數(shù)據(jù)庫(kù)
文章分享:http://muchs.cn/article48/dosjchp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營(yíng)銷App開(kāi)發(fā)、搜索引擎優(yōu)化、動(dòng)態(tài)網(wǎng)站、網(wǎng)站排名關(guān)鍵詞優(yōu)化

廣告

聲明:本網(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)

h5響應(yīng)式網(wǎng)站建設(shè)