欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

php添加數(shù)據(jù)語句 php數(shù)據(jù)表里怎么添加數(shù)據(jù)

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

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

創(chuàng)新互聯(lián)是一家專業(yè)提供察哈爾右翼后企業(yè)網(wǎng)站建設(shè),專注與網(wǎng)站設(shè)計(jì)、網(wǎng)站制作H5網(wǎng)站設(shè)計(jì)、小程序制作等業(yè)務(wù)。10年已為察哈爾右翼后眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)網(wǎng)站設(shè)計(jì)公司優(yōu)惠進(jìn)行中。

現(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ù)庫,并通過 $_POST 變量從表單取回值。然后,mysql_query() 函數(shù)執(zhí)行 INSERT INTO 語句,一條新的記錄會添加到數(shù)據(jù)庫表中。

下面是 "insert.php" 頁面的代碼:

?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數(shù)據(jù)庫添加、刪除、修改數(shù)據(jù)(mysql)

一、PHP操作MySql數(shù)據(jù)庫

新增數(shù)據(jù)

?php

$query

=

"INSERT

INTO

grade

(name,email,point,regdate)

VALUE

('

李三','yc60.com@gmail.com',,NOW())"

;

@mysql_query($query)

or

die(

'添加數(shù)據(jù)出錯(cuò):'

.mysql_error());

?

修改數(shù)據(jù)

?php

$query

=

"UPDATE

grade

SET

name='小可愛'

WHERE

id=6"

;

@mysql_query($query)

or

die(

'修改出錯(cuò):'

.mysql_error());

?

刪除數(shù)據(jù)

?php

$query

=

"DELETE

FROM

grade

WHERE

id=6";

@mysql_query($query)

or

die(

'刪除錯(cuò)誤:'

.mysql_error());

?

顯示數(shù)據(jù)

?php

$query

=

"SELECT

id,name,email,point

FROM

grade";

$result

=

@mysql_query($query)

or

die(

'查詢語句出錯(cuò):'

.mysql_error());

while

(!!

$row

=

mysql_fetch_array($result))

{

echo

$row[

'id'

].

'----'

.$row['name'

].'----'

.$row

['email'

].

'----'

.$row['point'

];

echo

'br

/

';

}

?

二、其他常用函數(shù)

mysql_f

etch_row()

:從結(jié)果集中取得一行作為枚舉數(shù)組

mysql_f

etch_assoc()

從結(jié)果集中取得一行作為關(guān)聯(lián)數(shù)組

mysql_f

etch_array()

從結(jié)果集中取得一行作為關(guān)聯(lián)數(shù)組,或數(shù)字?jǐn)?shù)組,或二者兼有

mysql_f

etch_lengths

()

取得結(jié)果集中每個(gè)輸出的長度

mysql_f

ield_name():

取得結(jié)果中指定字段的字段名

mysql_num_rows():

取得結(jié)果集中行的數(shù)目

mysql_num_f

ields():取得結(jié)果集中字段的數(shù)目

mysql_get_client_inf

o()

取得

MySQL

客戶端信息

mysql_get_host_info():

取得

MySQL

主機(jī)信息

mysql_get_proto_info():

取得

MySQL

協(xié)議信息

mysql_get_server_inf

o()

取得

MySQL

服務(wù)器信息

關(guān)于php添加語句

那只能先執(zhí)行insert插入,執(zhí)行插入后系統(tǒng)會返回一個(gè)產(chǎn)生的自遞增id值,對這個(gè)值md5加密后,再update

不可能在插入前得到這個(gè)id值的(先select最大id在低并發(fā)的情況下也行,高并發(fā)的話終究不夠嚴(yán)謹(jǐn))

php數(shù)據(jù)庫插入語句的問題

知友,第二張表代碼這樣改下:

?php

$dbname="wahaha";

$conn=mysql_connect("localhost","root","root")?or?die("連接MySQL服務(wù)器失敗。".mysql_error());

mysql_select_db($dbname)?or?die("選擇數(shù)據(jù)庫失敗!?".mysql_error());

$sql="insert?into?xinxi(xs_id,name,pwd,sex,class,xingqu,lianxi)?values?('15','張三','mima','男','軟件1班','打球','1234567')";

$rs=mysql_query($sql,$conn);

//以下可以省略

if($rs==1){

echo?'數(shù)據(jù)插入成功!影響行數(shù)ID:'.mysql_insert_id();

mysql_close($conn);

}

echo'?插入失敗';

mysql_close($conn);

?

你原來的操作失敗的原因是:你前面都對的,后面沒有執(zhí)行插入那個(gè)驅(qū)動命令,即少了個(gè)mysql_query()。

【打字不容易,記得給分!】

名稱欄目:php添加數(shù)據(jù)語句 php數(shù)據(jù)表里怎么添加數(shù)據(jù)
URL標(biāo)題:http://chinadenli.net/article18/hhhjgp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站建設(shè)、域名注冊、搜索引擎優(yōu)化、網(wǎng)頁設(shè)計(jì)公司建站公司、用戶體驗(yàn)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(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)

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