php寫入數(shù)據(jù)庫set php寫入數(shù)據(jù)庫數(shù)據(jù)json

php 接收到之后post數(shù)據(jù)寫入數(shù)據(jù)庫

form表單demo:task.html

“專業(yè)、務(wù)實(shí)、高效、創(chuàng)新、把客戶的事當(dāng)成自己的事”是我們每一個人一直以來堅(jiān)持追求的企業(yè)文化。 創(chuàng)新互聯(lián)是您可以信賴的網(wǎng)站建設(shè)服務(wù)商、專業(yè)的互聯(lián)網(wǎng)服務(wù)提供商! 專注于成都網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)、軟件開發(fā)、設(shè)計(jì)服務(wù)業(yè)務(wù)。我們始終堅(jiān)持以客戶需求為導(dǎo)向,結(jié)合用戶體驗(yàn)與視覺傳達(dá),提供有針對性的項(xiàng)目解決方案,提供專業(yè)性的建議,創(chuàng)新互聯(lián)建站將不斷地超越自我,追逐市場,引領(lǐng)市場!

fieldset id="setFiled"

legend發(fā)布任務(wù)/legend

form action="registr.php" method="post" id="steForm"

label任務(wù)類型:/labelbr

input type="text" name="type"? id="taskType" placeholder="請選擇任務(wù)類型"/br

label酬nbsp;nbsp;金:/labelbr

input type="number" name="money" id="forMoney" min="1" max="1000"/label元/labelbr

label截止時(shí)間:/labelbr

input type="datetime" name="time" id="timeSubmit"/span data-year="" data-month="" data-date="" id="showDate"/spanbr

label詳細(xì)描述:/labelbr

textarea maxlength="512" name="textAray" id="msgArea"/textareabr

input type="submit" name="subMit" id="forSub" value="點(diǎn)擊發(fā)布" /

/form

擴(kuò)展資料

php接收POST數(shù)據(jù)的三種方式

1、$_POST 方式接受數(shù)據(jù)

$_POST 方式是由通過HTTP的POST方法傳遞過來的數(shù)據(jù)組成的數(shù)組,是一個自動全局變量。

注:只能接收Content-Type:application/x-www-form-urlencode提交的數(shù)據(jù)。也就是只能接收表單過來的數(shù)據(jù)。

2、GLOBLES[‘HTTP_RAW_POST_DATA’]

如果訪問原始POST數(shù)據(jù)不是php能夠識別的文檔類型,比如:text/xml 或者soap等等,可以用$GLOBLES[‘HTTP_RAW_POST_DATA’]來接收,$HTTP_RAW_POST_DATA變量包含有原始POST數(shù)據(jù)。此變量僅在碰到未識別的MIME數(shù)據(jù)時(shí)產(chǎn)生。

注:$HTTP_RAW_POST_DATA對于enctype=”multipart/form-data”表單數(shù)據(jù)不可用,也就是說使用$HTTP_RAW_POST_DATA無法接受網(wǎng)頁表單post過來的數(shù)據(jù)。

3、file_get_contents(“php://input”);

如果訪問原始POST數(shù)據(jù),更好的方法是使用file_get_content(“php://input”);對于未指定Content-Type的POST數(shù)據(jù),可以使用該方法讀取POST原始數(shù)據(jù),包括二進(jìn)制流也可以和$HTTP_RAW_POST_DATA比起來。它帶來的生存眼里更小,并且不需要任何特殊的php.ini設(shè)置。

注:php://input不能用于 enctype=”multipart/form-data”

例如:$postStr = file_get_contents("php://input"); //獲取POST數(shù)據(jù)

PHP插入mysql數(shù)據(jù)庫亂碼

亂碼主要以下幾個原因:

1。數(shù)據(jù)表中,表本身的編碼 和 字段編碼,均為UTF8。

2。在寫入數(shù)據(jù)等數(shù)據(jù)庫操作前,發(fā)送語句 'set names utf8'

3。PHP文件都是UTF8編碼,無簽名(無BOM)

4。頁面上使用header或meta保證輸出的頁面是UTF8編碼。meta http-equiv="Content-Type" content="text/html; charset=utf-8" /

鮮少老師

php表單寫入mysql數(shù)據(jù)庫的代碼

!--表單文件,拷入index.php--

!DOCTYPE?html

html

head

style

label{display:inline-block;width:100px;margin-bottom:10px;}

/style

titleAdd?students/title

/head

body

!--?數(shù)據(jù)庫用mysqli?面向過程調(diào)用方法--

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

!--數(shù)據(jù)庫用mysqli?面向過程調(diào)用方法

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

--

!--數(shù)據(jù)庫用PDO調(diào)用方法

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

--

labelFirst?Name/label

input?type="text"?name="first_name"?/

br?/

labelLast?Name/label

input?type="text"?name="last_name"?/

br?/

labeldepartment/label

input?type="text"?name="department"?/

br?/

labelEmail/label

input?type="text"?name="email"?/

br?/

input?type="submit"?value="Add?students"

/form

/body

/html

------------------------------

?php

//拷貝命名為write2db.php,數(shù)據(jù)庫用mysqli?面向過程調(diào)用方法

//print_r($_POST);

//?create?a?variable

$first_name=$_POST['first_name'];

$last_name=$_POST['last_name'];

$department=$_POST['department'];

$email=$_POST['email'];

//調(diào)試用

echo?"Your?input:?";

echo?$first_name;

echo?'br?/';

echo?$last_name;

echo?'br?/';

echo?$department;

echo?'br?/';

echo?$email;

echo?'br?/';

$servername?=?"localhost";

//Your?database?username?and?password

//$username?=?"username";

//$password?=?"password";

$username?=?"tester";

$password?=?"testerPassword";

//your?database?name

$dbname?=?"test";

$tablename?="student";

//?Create?connection

$connect?=?mysqli_connect($servername,?$username,?$password,?$dbname);

if?(!$connect)?{

die("Connection?failed:?"?.?mysqli_connect_error());

}

//Execute?the?query

$sql="INSERT?INTO?$tablename?(first_name,last_name,department,email)

VALUES('$first_name','$last_name','$department','$email')";

if?(mysqli_query($connect,?$sql))?{

echo?"Hooray!?New?record?is?inserted?to?database?successfully.?Please?check?database.";

}?else?{

echo?"Error:?"?.?$sql?.?"br?/"?.?mysqli_error($connect);

}

mysqli_close($connect);

?

?php

//拷貝命名為write2db_sqlio.php,數(shù)據(jù)庫用mysqli?面向?qū)ο笳{(diào)用方法

//print_r($_POST);

//?create?a?variable

$first_name=$_POST['first_name'];

$last_name=$_POST['last_name'];

$department=$_POST['department'];

$email=$_POST['email'];

//調(diào)試用

echo?"Your?input:?";

echo?$first_name;

echo?'br?/';

echo?$last_name;

echo?'br?/';

echo?$department;

echo?'br?/';

echo?$email;

echo?'br?/';

$servername?=?"localhost";

//Your?database?username?and?password

//$username?=?"username";

//$password?=?"password";

$username?=?"tester";

$password?=?"testerPassword";

//database?name

$dbname?=?"test";

$tablename?="student";

//?Create?connection

$conn?=?new?mysqli($servername,?$username,?$password,?$dbname);

//?Check?connection

if?($conn-connect_error)?{

die("Connection?failed:?"?.?$conn-connect_error);

}?

$sql="INSERT?INTO?$tablename?(first_name,last_name,department,email)

VALUES('$first_name','$last_name','$department','$email')";

if?($conn-query($sql)?===?TRUE)?{

echo?"New?record?created?successfully";

}?else?{

echo?"Error:?"?.?$sql?.?"br"?.?$conn-error;

}

$conn-close();

?

?php

//拷貝為文件write2db_pdo.php,數(shù)據(jù)庫用PDO調(diào)用方法

//print_r($_POST);

a?variable

$first_name=$_POST['first_name'];

$last_name=$_POST['last_name'];

$department=$_POST['department'];

$email=$_POST['email'];

//調(diào)試用

echo?"Your?input:?";

echo?$first_name;

echo?'br?/';

echo?$last_name;

echo?'br?/';

echo?$department;

echo?'br?/';

echo?$email;

echo?'br?/';

$servername?=?"localhost";

//Your?database?username?and?password

//$username?=?"username";

//$password?=?"password";

$username?=?"tester";

$password?=?"testerPassword";

//your?database?name

$dbname?=?"test";

$tablename?="student";

//?Create?connection

try?{

$conn?=?new?PDO("mysql:host=$servername;dbname=$dbname",?$username,?$password);

//?set?the?PDO?error?mode?to?exception

$conn-setAttribute(PDO::ATTR_ERRMODE,?PDO::ERRMODE_EXCEPTION);

$sql="INSERT?INTO?$tablename?(first_name,last_name,department,email)

VALUES('$first_name','$last_name','$department','$email')";

//?use?exec()?

$conn-exec($sql);

echo?"New?record?created?successfully";

}

catch(PDOException?$e)

{

echo?$sql?.?"br"?.?$e-getMessage();

}

$conn?=?null;

?

--創(chuàng)建數(shù)據(jù)庫test,?將此文件存為test.sql?導(dǎo)入數(shù)據(jù)庫,或者手動創(chuàng)建表結(jié)構(gòu)

--?phpMyAdmin?SQL?Dump

--?version?4.7.4

--?

--

--?Host:?127.0.0.1:3306

--?Generation?Time:?Mar?12,?2018?at?04:04?AM

--?Server?version:?5.7.19

--?PHP?Version:?7.1.9

SET?SQL_MODE?=?"NO_AUTO_VALUE_ON_ZERO";

SET?AUTOCOMMIT?=?0;

START?TRANSACTION;

SET?time_zone?=?"+00:00";

/*!40101?SET?@OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT?*/;

/*!40101?SET?@OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS?*/;

/*!40101?SET?@OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION?*/;

/*!40101?SET?NAMES?utf8mb4?*/;

--

--?Database:?`test`

--

--?--------------------------------------------------------

--

--?Table?structure?for?table?`student`

--

DROP?TABLE?IF?EXISTS?`student`;

CREATE?TABLE?IF?NOT?EXISTS?`student`?(

`id`?tinyint(3)?UNSIGNED?NOT?NULL?AUTO_INCREMENT,

`first_name`?varchar(20)?NOT?NULL,

`last_name`?varchar(20)?NOT?NULL,

`department`?varchar(50)?NOT?NULL,

`email`?varchar(50)?NOT?NULL,

PRIMARY?KEY?(`id`)

)?ENGINE=MyISAM?AUTO_INCREMENT=2?DEFAULT?CHARSET=utf8;

--

--?Dumping?data?for?table?`student`

--

INSERT?INTO?`student`?(`id`,?`first_name`,?`last_name`,?`department`,?`email`)?VALUES

(1,?'first1',?'last1',?'cs',?'1985@qq.com');

COMMIT;

/*!40101?SET?CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT?*/;

/*!40101?SET?CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS?*/;

/*!40101?SET?COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION?*/;

php?寫入數(shù)據(jù)庫?例子

?php

//?以?MySQL?為例:

mysql_connect('127.0.0.1',?'root',?'root',?3306);??//?連接數(shù)據(jù)庫

mysql_select_db('test');???????????????????????????//?選擇數(shù)據(jù)庫

mysql_query('set?names?utf8');?????????????????????//?執(zhí)行SQL

//?插入數(shù)據(jù)語句

$sql?=?"INSERT?INTO?table?(username,?password)?VALUES?('Jack@163.com',?'123456')";

$r?=?mysql_query($sql);

if?(mysql_affected_rows())?{

echo?'新增成功';

}?else?{

echo?mysql_error();

}

本文標(biāo)題:php寫入數(shù)據(jù)庫set php寫入數(shù)據(jù)庫數(shù)據(jù)json
轉(zhuǎn)載源于:http://www.muchs.cn/article46/doeegeg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供軟件開發(fā)、網(wǎng)站內(nèi)鏈、電子商務(wù)、網(wǎng)站維護(hù)、定制開發(fā)、網(wǎng)站營銷

廣告

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

營銷型網(wǎng)站建設(shè)