當前位置:才華齋>計算機>php語言>

如何實現PHP獲取表單資料與HTML嵌入PHP指令碼

php語言 閱讀(6.26K)

導語:如何實現PHP獲取表單資料與HTML嵌入PHP指令碼,下面是小編給大家提供的操作講解,大家可以參考閱讀,更多詳情請關注應屆畢業生考試網。

如何實現PHP獲取表單資料與HTML嵌入PHP指令碼

常用的自動全域性變數如下所示:

  1、GET方式

功能:獲取get方式提交的資料

格式:$_GET[“formelement”]

  2、POST方式

功能:獲取post方式提交的資料

格式:$_POST[“formelement”]

  3、REQUEST方式

功能:獲取任意方式提交的資料,$_REQUEST自動全域性變數包含了所有GET、POST、COOKIE和FILE的`資料,如不關心資料來源。

格式:$_REQUEST[“formelement”]

複選框 、列表框(名稱採用陣列形式如:"select[]",在獲取其值的時候直接使用$_POST["select"]即可)

<!doctype html>

<html>

<head>

<meta charset="utf-8">

<title>無標題文件</title>

</head>

<body>

<!--獲取表單資料的兩種方法-->

<!--post-->

<form method="post" action="" name="form1">

<table border="1" width="400" cellpadding="0" cellspacing="0">

<tr>

<td height="30"> 使用者名稱:<input name="txtName" type="text" size="12">

密碼:<input name="txtPsd" type="password" size="12">

<input type="submit" name="SubmitBtn" value="提交">

</td>

</tr>

</table>

</form><br/>

<!--get URL的長度需要限定在1M範圍內,否則會擷取-->

<!--可以使用urlencode與urldecode對URL進行編解碼-->

<form method="get" action="" name="form2">

<table border="1" width="400" cellpadding="0" cellspacing="0">

<tr>

<td width="400" height="30"> 訂單號:<input name="txtFrame" type="text" size="12">

<input type="submit" name="SubmitBtn">

</td>

</tr>

</table>

</form>

<!--在Web頁面中嵌入PHP指令碼-->

<?php

$strTxt = '男';

?>

<input type="text" value="<?php echo "strTxt"; ?>">

</body>

<?php

echo '使用者名稱: '.$_POST["txtName"]." 密碼:".$_POST['txtPsd'];

echo '訂單號:'.$_GET["txtFrame"];

?>

</html>