文本的名字加上中括號即可實現(xiàn),比如: name="contents" = name="contents[]",最后提交獲取到的數(shù)據(jù)是一個數(shù)組形式的。
成都創(chuàng)新互聯(lián)公司專注于網(wǎng)站建設(shè)|成都網(wǎng)站維護|優(yōu)化|托管以及網(wǎng)絡(luò)推廣,積累了大量的網(wǎng)站設(shè)計與制作經(jīng)驗,為許多企業(yè)提供了網(wǎng)站定制設(shè)計服務(wù),案例作品覆蓋成都茶藝設(shè)計等行業(yè)。能根據(jù)企業(yè)所處的行業(yè)與銷售的產(chǎn)品,結(jié)合品牌形象的塑造,量身設(shè)計品質(zhì)網(wǎng)站。
代碼如下:
form name="form1" method="post" action="index.php?action=ok"
1.input type="text" name="contents[]" value=""
2.input type="text" name="contents[]" value=""
3.input type="text" name="contents[]" value=""
input type="submit" value="提交"
/form
?php
if($_GET['action'] == 'ok'){
$contents = $_POST['contents'];
print_r($contents);
}
?
提交的數(shù)據(jù)使用時,遍歷即可。
一般是分兩個form 提交到兩個不同的地,如果要做在一個form里面,就需要用js來實踐提交到目標(biāo)地址
可以的,
1、用多行文本正常提交
2、在后臺把提交的數(shù)據(jù)按回車
換行符
或空格等(具體看你的輸入情況)拆分成數(shù)組
3、驗證就行了
有問題再聯(lián)系
有可能是程序問題,比如循環(huán)語句中執(zhí)行sql 檢查你的程序文件;
也有可能是表單重復(fù)提交造成的。建議在表單提交成功時做一個跳轉(zhuǎn)頁面這樣可以解決這種情況的發(fā)生
多個提交和一個提交的道理是相同的,只是一些細節(jié)上要注意。
提交一個你懂了,我還是提一下,表單是:
form
input type=text name=name
input type=text name=sex
input type=text name=age
input type=text name=address
/form
PHP存數(shù)據(jù)庫的語句是:
$sql="insert into tab(...) values ($_POST[...])";//省略字段和值
那么多個提交的方法一,表單是:
form
input type=text name=name1input type=text name=sex1input type=text name=age1input type=text name=address1
input type=text name=name2input type=text name=sex2input type=text name=age2input type=text name=address2
/form
PHP存數(shù)據(jù)庫語句是:
$sql="insert into tab(...) values ($_POST[...1])";//省略字段和值
mysql_query($sql);
$sql="insert into tab(...) values ($_POST[...2])";//省略字段和值
mysql_query($sql);
上面方法一寫的例子是兩條,多條的方法相同,技巧就是輸出表單使用JS的循環(huán),存盤的PHP代碼也可以循環(huán),并且能夠判斷為空的就不提交,比如表單20條,只填了5條,就只存5條到數(shù)據(jù)庫。
方法二是使用數(shù)組,表單:
form
input type=text name=nameinput type=text name=sexinput type=text name=ageinput type=text name=address
input type=text name=nameinput type=text name=sexinput type=text name=ageinput type=text name=address
input type=text name=nameinput type=text name=sexinput type=text name=ageinput type=text name=address
/form
PHP代碼是:
for ($i=0;$icount($_POST["name"]);$i++)
if ($_POST["name"][$i]!='')
{
$sql="insert into tab(...) values ($_POST[...][$i])";//省略字段和值
mysql_query($sql);
}
這樣表單可以寫任意多行,PHP里面是數(shù)組,能夠自動獲取有多少數(shù)據(jù)。
首先form表單
form action="" method="post"
input type=text name=name[]input type=text name=sex[]br/
input type=text name=name[]input type=text name=sex[]br/
input type="Submit" value=" 提交" size="50"/
/form
然后php頁面,
?php
mysql_connect("localhost","root","password");
mysql_select_db("databasename");
mysql_query("set names 'utf8'");
$name=$_POST['name'];
$sex=$_POST['sex'];
foreach($name as $key=$value){
mysql_query("insert into test(name,sex) values('$value','".$sex[$key]."')");
}
?
有問題的話,追加問題
網(wǎng)頁題目:php提交表單兩條數(shù)據(jù) php自動提交表單
URL地址:http://chinadenli.net/article28/hgspcp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信小程序、營銷型網(wǎng)站建設(shè)、標(biāo)簽優(yōu)化、Google、網(wǎng)站收錄、網(wǎng)站導(dǎo)航
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)