!DocTYpe HTML
成都創(chuàng)新互聯(lián)專注于企業(yè)營(yíng)銷型網(wǎng)站、網(wǎng)站重做改版、利通網(wǎng)站定制設(shè)計(jì)、自適應(yīng)品牌網(wǎng)站建設(shè)、HTML5、商城網(wǎng)站制作、集團(tuán)公司官網(wǎng)建設(shè)、外貿(mào)網(wǎng)站制作、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁(yè)設(shè)計(jì)等建站業(yè)務(wù),價(jià)格優(yōu)惠性價(jià)比高,為利通等各大城市提供網(wǎng)站開(kāi)發(fā)制作服務(wù)。
html
body
?php
$nameErr = "";
$name = $email = $gender = $comment = $website = "";
if($_SERVER["REQUEST_METHOD"] == "POST"){
if(empty($_POST["name"])){
$nameErr = "Name is required";
}else{
$name = $_POST["name"];
}
$email = $_POST["email"];
$website = $_POST["website"];
$comment = $_POST["comment"];
$gender = $_POST["gender"];
}
?
form method ="post" action ="?php echo htmlspecialchars($_SERVER["PHP_SELF"]) ;?";
Name: input type="text" name="name" value ="?php echo $name?"span class ="error"?php echo $nameErr;?/span
brbrbr
E-mail: input type="text" name="email"
brbrbr
Website: input type="text" name="website"
brbrbr
Comment: textarea name="comment" rows="5" cols="40"/textarea
brbrbr
input type = "radio" name="gender" value = "man"man
input type = "radio" name="gender" value = "woman"woman
br
input type = "submit"
/form
?php
echo "you have enter:";
echo "br";
echo $name;
echo "br";
echo $email;
echo "br";
echo $website;
echo "br";
echo $comment;
echo "br";
echo $gender;
?
/body
/html
我自己寫(xiě)的一個(gè)簡(jiǎn)單例子,用的是form 表單的post 傳遞
action ="?php echo htmlspecialchars($_SERVER["PHP_SELF"]) ;?
可以替換成你想跳轉(zhuǎn)的php文件,
望采納,不明白再問(wèn)我
PHP把表單提交到本頁(yè),這個(gè)的話,我們是通過(guò)form action="提交的文件名"來(lái)實(shí)現(xiàn)的,還有一個(gè)傳值的方式,post或者是get可以通過(guò)METHOD來(lái)實(shí)現(xiàn)的,這里我寫(xiě)一段代碼:
html
head/head
body
form action='文件名' method="post"
姓名input type='text' value=""
密碼input type='text' value=""
emailinput type='text' value=""
/form
/body
/html
創(chuàng)建go.php,代碼如下
?php
@$username = $_POST['name'];
@$usermessage = $_POST['message'];
if(!empty($username) || !empty($usermessage)){
echo "您的姓名:".$username.",您的留言內(nèi)容:".$usermessage;
}else{
echo 'form action="go.php" method="post"
您的姓名:input type="text" name="name"brbr
留言內(nèi)容:input type="text" name="message"
button提交/button
/form';
案例截圖:
1:首先要使用PHP的超全局變量 $_GET 和 $_POST 用于收集表單數(shù)據(jù)(form-data) 2:然后使用INSERT INTO 語(yǔ)句用于向數(shù)據(jù)庫(kù)表中插入新記錄。 具體示例: (1)首先創(chuàng)建了一個(gè)名為 "Persons" 的表,有三個(gè)列:"Firstname", "Lastname" 以及 "Age"。
如果您想在PHP表單中實(shí)現(xiàn)提交到多個(gè)表的不同字段,可以使用如下步驟來(lái)實(shí)現(xiàn):
在表單中定義相應(yīng)的字段,用于獲取用戶輸入的數(shù)據(jù)。
使用PHP代碼從表單中獲取用戶輸入的數(shù)據(jù)。
使用PHP中的數(shù)據(jù)庫(kù)操作函數(shù)(例如MySQLi或PDO),連接到數(shù)據(jù)庫(kù),并且向不同的表插入數(shù)據(jù)。
例如,如果您想插入用戶名和電子郵件到users表,并插入用戶的年齡和住址到profiles表,可以這樣寫(xiě):
// 獲取用戶輸入的數(shù)據(jù)
$username = $_POST['username'];
$email = $_POST['email'];
$age = $_POST['age'];
$address = $_POST['address'];
// 連接到數(shù)據(jù)庫(kù)
$conn = mysqli_connect('localhost', 'username', 'password', 'database');
// 插入用戶名和電子郵件到users表
$sql = "INSERT INTO users (username, email) VALUES ('$username', '$email')";
mysqli_query($conn, $sql);
// 插入用戶的年齡和住址到profiles表
$sql = "INSERT INTO profiles (age, address) VALUES ('$age', '$address')";
mysqli_query($conn, $sql);
一、用file_get_contents以get方式獲取內(nèi)容,需要輸入內(nèi)容為:
1、?php
2、$url='';
3、$html=file_get_contents($url);
4、echo$html;
5、?
二、用file_get_contents函數(shù),以post方式獲取url,需要輸入內(nèi)容為
1、?php
2、$url='';
3、$data=array('foo'='bar');
4、$data=http_build_query($data);
5、$opts=array(
6、'http'=array(
7、?'method'='POST',
8、?'header'="Content-type:application/x-www-form-urlencoded\r\n".
9、??????????"Content-Length:".strlen($data)."\r\n",
10、?'content'=$data
11、)
12、);
13、$ctx=stream_context_create($opts);
14、$html=@file_get_contents($url,'',$ctx);
15、?
三、用fopen打開(kāi)url,以get方式獲取內(nèi)容,需要輸入內(nèi)容為
1、?php
2、$fp=fopen($url,'r');
3、$header=stream_get_meta_data($fp);//獲取信息
4、while(!feof($fp)){
5、$result.=fgets($fp,1024);
6、}
7、echo"urlheader:{$header}br":
8、echo"urlbody:$result";
9、fclose($fp);
10、?
四、用fopen打開(kāi)url,以post方式獲取內(nèi)容,需要輸入內(nèi)容為
1、?php
2、$data=array('foo2'='bar2','foo3'='bar3');
3、$data=http_build_query($data);
4、$opts=array(
5、'http'=array(
6、'method'='POST',
7、'header'="Content-type:application/x-www-form-urlencoded\r\nCookie:cook1=c3;cook2=c4\r\n".
8、"Content-Length:".strlen($data)."\r\n",
9、'content'=$data
10、)
11、);
12、$context=stream_context_create($opts);
13、$html=fopen(';id2=i4','rb',false,$context);
14、$w=fread($html,1024);
15、echo$w;
16、?
五、用fsockopen函數(shù)打開(kāi)url,以get方式獲取完整的數(shù)據(jù),包括header和body,需要輸入內(nèi)容為
1、?php
2、functionget_url($url,$cookie=false)
3、{
4、$url=parse_url($url);
5、$query=$url[path]."?".$url[query];
6、echo"Query:".$query;
7、$fp=fsockopen($url[host],$url[port]?$url[port]:80,$errno,$errstr,30);
8、if(!$fp){
9、returnfalse;
10、}else{
11、$request="GET$queryHTTP/1.1\r\n";
12、$request.="Host:$url[host]\r\n";
13、$request.="Connection:Close\r\n";
14、if($cookie)$request.="Cookie:??$cookie\n";
15、$request.="\r\n";
16、fwrite($fp,$request);
17、while(!@feof($fp)){
18、$result.=@fgets($fp,1024);
19、}
20、fclose($fp);
21、return$result;
22、}
23、}
24、//獲取url的html部分,去掉header
25、functionGetUrlHTML($url,$cookie=false)
26、{
27、$rowdata=get_url($url,$cookie);
28、if($rowdata)
29、{
30、$body=stristr($rowdata,"\r\n\r\n");
31、$body=substr($body,4,strlen($body));
32、return$body;
33、}
34、?returnfalse;
35、}
36、?
參考資料:
php-file_get_contents
本文名稱:php頁(yè)面提交表單數(shù)據(jù) thinkphp表單提交
文章鏈接:http://m.kartarina.com/article26/hjihcg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供小程序開(kāi)發(fā)、搜索引擎優(yōu)化、網(wǎng)站設(shè)計(jì)公司、面包屑導(dǎo)航、做網(wǎng)站、網(wǎng)站排名
聲明:本網(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)