方法1、最常見的方法是:$_POST['fieldname'];

創(chuàng)新互聯(lián)咨詢熱線:028-86922220,為您提供成都網(wǎng)站建設(shè)網(wǎng)頁設(shè)計(jì)及定制高端網(wǎng)站建設(shè)服務(wù),創(chuàng)新互聯(lián)網(wǎng)頁制作領(lǐng)域10年,包括成都資質(zhì)代辦等多個(gè)方面擁有多年的網(wǎng)站制作經(jīng)驗(yàn),選擇創(chuàng)新互聯(lián),為網(wǎng)站保駕護(hù)航!
說明:只能接收Content-Type:
application/x-www-form-urlencoded提交的數(shù)據(jù)
解釋:也就是表單POST過來的數(shù)據(jù)
方法2、file_get_contents("php://input");
說明:
允許讀取
POST
的
原始數(shù)據(jù)
。
和
$HTTP_RAW_POST_DATA
比起來,它給內(nèi)存帶來的壓力較小,并且不需要任何特殊的
php.ini
設(shè)置。
php://input
不能用于
enctype="multipart/form-data"。
解釋:
對(duì)于未指定
Content-Type
的POST數(shù)據(jù),則可以使用file_get_contents(“php://input”);來獲取原始數(shù)據(jù)。
事實(shí)上,用PHP接收POST的任何數(shù)據(jù)都可以使用本方法。而不用考慮Content-Type,包括
二進(jìn)制文件
流也可以。
所以用方法二是最保險(xiǎn)的方法
方法3、$GLOBALS['HTTP_RAW_POST_DATA'];
說明:
總是產(chǎn)生
$HTTP_RAW_POST_DATA
變量包含有原始的
POST
數(shù)據(jù)。
此變量?jī)H在碰到未識(shí)別
MIME
類型的數(shù)據(jù)時(shí)產(chǎn)生。
$HTTP_RAW_POST_DATA
對(duì)于
enctype="multipart/form-data"
表單數(shù)據(jù)不可用
如果post過來的數(shù)據(jù)不是PHP能夠識(shí)別的,可以用
$GLOBALS['HTTP_RAW_POST_DATA']來接收,
比如
text/xml
或者
soap
等等
解釋:
$GLOBALS['HTTP_RAW_POST_DATA']存放的是POST過來的原始數(shù)據(jù)。
$_POST或
$_REQUEST
存放的是
PHP以key=value的形式格式化以后的數(shù)據(jù)。
但$GLOBALS['HTTP_RAW_POST_DATA']中是否保存POST過來的數(shù)據(jù)取決于centent-Type的設(shè)置,即POST數(shù)據(jù)時(shí)
必須顯式示指明Content-Type:
application/x-www-form-urlencoded,POST的數(shù)據(jù)才會(huì)存放到
$GLOBALS['HTTP_RAW_POST_DATA']中
代碼如下:?View
Code
PHP
include("conn.php");//調(diào)用數(shù)據(jù)庫連接文件
echo
"table
width=572
height=56
border=0
cellspacing=1
";
//創(chuàng)建html表格
echo
"tr
bgcolor=#9999FF";
echo
"th
width=33
scope=colid/th";
echo
"th
width=100
scope=coluser_name/th
";
echo
"th
width=100
scope=coluser_pass/th
";
echo
"th
width=100
scope=colstaus/th";
echo
"th
width=100
scope=colinsert_time/th";
echo
"/tr";
$SQL
=
"select
*
from
user_info";
$query
=
mysql_query($SQL);
//SQL查詢語句
while
($row
=
mysql_fetch_array($query)){
//使用while循環(huán)mysql_fetch_array()并將數(shù)據(jù)返回?cái)?shù)組
echo
"tr
onmouseout=this.style.backgroundColor=''
onMouseOver=this.style.backgroundColor='#99CC33'
bgcolor=#CCCCCC";
echo
"td$row[0]/td";
//輸出數(shù)組中數(shù)據(jù)
echo
"td$row[1]/td";
echo
"td$row[2]/td";
echo
"td$row[3]/td";
echo
"td$row[4]/td";
echo
"/tr";
}
echo
"/table";輸出記錄截圖
獲取ppq數(shù)據(jù)庫的所有表名的代碼:
?php
$server='localhost';
$user='root';
$pass='12345';
$dbname='ppq';
$conn=mysql_connect($server,$user,$pass);
if(!$conn)
die("數(shù)據(jù)庫系統(tǒng)連接失敗!");
$result=mysql_list_tables($dbname);
if(!$result)
die("數(shù)據(jù)庫連接失敗!");
while($row=mysql_fetch_row($result))
{
echo
$row[0]."
";
}
mysql_free_result($result);
?
mysql_list_tables
(PHP
3,
PHP
4
,
PHP
5)
mysql_list_tables
--
列出
MySQL
數(shù)據(jù)庫中的表
說明
resource
mysql_list_tables
(
string
database
[,
resource
link_identifier])
mysql_list_tables()
接受一個(gè)數(shù)據(jù)庫名并返回和
mysql_query()
函數(shù)很相似的一個(gè)結(jié)果指針。用
mysql_fetch_array()或者用mysql_fetch_row()來獲得一個(gè)數(shù)組,數(shù)組的第0列就是數(shù)組名,當(dāng)獲取不到時(shí)
mysql_fetch_array()或者用mysql_fetch_row()返回
FALSE。
//連接數(shù)據(jù)庫
if(!$con = mysql_connect("localhost","root","root")){die(mysql_error());}
mysql_select_db("ali_xt");
mysql_query('set names utf8');
//找出ali_admin表的字段
$res = mysql_query('show columns from ali_admin');
//將數(shù)據(jù)給弄出來
$data = array();
while ($row = mysql_fetch_assoc($res, MYSQL_NUM)) {
$data[] = $row;
}
//隨機(jī)個(gè)數(shù),默認(rèn)5
$rand_times = 5;
$rand_times = count($data)$rand_times?count($data):$rand_times;
$result = array();
for( $i=0;$i$rand_times;$i++ ){
$result[] = $data[rand(0,count($data)-1)][0];
}
echo "pre";
print_r($result); //輸出5個(gè)隨機(jī)字段
mysql_close($con);
//純手寫的,不明白可以問我,記得給分
用戶在表格form
中填寫數(shù)據(jù),然后提交到一個(gè)php文件,PHP文件使用函數(shù)獲取數(shù)據(jù)
form action="welcome.php" method="post"
Name: input type="text" name="name"br
E-mail: input type="text" name="email"br
input type="submit" value="提交"
/form用戶填寫完username后提交到welcome.php文件,在welcome.php文件中,
html
body
Welcome ?php echo $_POST["name"]; ?br
Your email address is: ?php echo $_POST["email"]; ?
/body
/html$_POST["name"]就是用戶輸入的名字
$con=mysql_connect('localhost','root','');//數(shù)據(jù)庫信息
mysql_select_db('shop');//數(shù)據(jù)庫名
mysql_query("set?names?utf8");//設(shè)置字符集編碼
$sql="select?goods_name,goods_number,shop_price?from?goods";//查詢語句
$res=mysql_query($sql);//執(zhí)行查詢
while($row=mysql_fetch_assoc($res)){
$rows[]=$row;//接受結(jié)果集
}
//遍歷數(shù)組
foreach($rows?as?$key=$v){
echo?$v['goods_name']."---".$v['goods_number']."---".$v['shop_price']."";
}
布局可以自己寫的。數(shù)據(jù)從foreach循環(huán)里取出。
文章題目:php語句怎么獲取數(shù)據(jù),php怎么獲取數(shù)據(jù)庫中的數(shù)據(jù)
當(dāng)前地址:http://chinadenli.net/article33/dsgcops.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供靜態(tài)網(wǎng)站、搜索引擎優(yōu)化、關(guān)鍵詞優(yōu)化、網(wǎng)頁設(shè)計(jì)公司、商城網(wǎng)站、App開發(fā)
聲明:本網(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)