文本的名字加上中括號(hào)即可實(shí)現(xiàn),比如: name="contents" = name="contents[]",最后提交獲取到的數(shù)據(jù)是一個(gè)數(shù)組形式的。
成都創(chuàng)新互聯(lián)公司專注于網(wǎng)站建設(shè)|成都網(wǎng)站維護(hù)|優(yōu)化|托管以及網(wǎng)絡(luò)推廣,積累了大量的網(wǎng)站設(shè)計(jì)與制作經(jīng)驗(yàn),為許多企業(yè)提供了網(wǎng)站定制設(shè)計(jì)服務(wù),案例作品覆蓋成都茶藝設(shè)計(jì)等行業(yè)。能根據(jù)企業(yè)所處的行業(yè)與銷售的產(chǎn)品,結(jié)合品牌形象的塑造,量身設(shè)計(jì)品質(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ù)使用時(shí),遍歷即可。
一般是分兩個(gè)form 提交到兩個(gè)不同的地,如果要做在一個(gè)form里面,就需要用js來(lái)實(shí)踐提交到目標(biāo)地址
可以的,
1、用多行文本正常提交
2、在后臺(tái)把提交的數(shù)據(jù)按回車
換行符
或空格等(具體看你的輸入情況)拆分成數(shù)組
3、驗(yàn)證就行了
有問(wèn)題再聯(lián)系
有可能是程序問(wèn)題,比如循環(huán)語(yǔ)句中執(zhí)行sql 檢查你的程序文件;
也有可能是表單重復(fù)提交造成的。建議在表單提交成功時(shí)做一個(gè)跳轉(zhuǎn)頁(yè)面這樣可以解決這種情況的發(fā)生
多個(gè)提交和一個(gè)提交的道理是相同的,只是一些細(xì)節(jié)上要注意。
提交一個(gè)你懂了,我還是提一下,表單是:
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ù)庫(kù)的語(yǔ)句是:
$sql="insert into tab(...) values ($_POST[...])";//省略字段和值
那么多個(gè)提交的方法一,表單是:
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ù)庫(kù)語(yǔ)句是:
$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ù)庫(kù)。
方法二是使用數(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ù)組,能夠自動(dòng)獲取有多少數(shù)據(jù)。
首先f(wàn)orm表單
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頁(yè)面,
?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èn)題的話,追加問(wèn)題
網(wǎng)頁(yè)題目:php提交表單兩條數(shù)據(jù) php自動(dòng)提交表單
URL地址:http://muchs.cn/article28/hgspcp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信小程序、營(yíng)銷型網(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)請(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)
猜你還喜歡下面的內(nèi)容