首页  >  文章  >  后端开发  >  PHP分析POST重复值

PHP分析POST重复值

WBOY
WBOY原创
2016-06-23 13:56:061046浏览

客户端HTML

<form action="new.php" method="post">	<input name="part" type="text" />	<input name="transysno" type="text" />	<input name="tranlineid" type="text" />        <input name="count" type="text" />	<input name="part" type="text" />	<input name="transysno" type="text" />	<input name="tranlineid" type="text" />        <input name="count" type="text" />	<input type="submit" name="post" value="提交" /></form>


怎么在PHP服务端判断 两组part,transysno,tranlineid 是否相同 ,如果相同则获取相同count的和


回复讨论(解决方案)

php 要求传入的同名变量写作数组形式
所以你的表单中的两组同名控件,只会有一组被 php 接收到

php 要求传入的同名变量写作数组形式
所以你的表单中的两组同名控件,只会有一组被 php 接收到



写成数组 之后 怎么能 分析出 四个变量中三个变量的值是否相同 然后判断是否合并他们的count呢

提交后 print_r($_POST); 就知道该怎么做了

客户端html

<form action="news.php" method="post">    <input name="part[]" type="text" />    <input name="transysno[]" type="text" />    <input name="tranlineid[]" type="text" />        <input name="count[]" type="text" />     <input name="part[]" type="text" />    <input name="transysno[]" type="text" />    <input name="tranlineid[]" type="text" />        <input name="count[]" type="text" />    <input type="submit" name="post" value="提交" /></form>


news.php
if($_POST['part'][0]==$_POST['part'][1] && $_POST['transysno'][0]==$_POST['transysno'][1] && $_POST['tranlineid'][0]==$_POST['tranlineid'][1]){    echo ($_POST['count'][0] + $_POST['count'][1]);}else{    echo 'part,transysno,tranlineid not match';}

结贴 参阅了 http://bbs.csdn.net/topics/360243533

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn