我正在尝试处理一个大表单,并且遇到了一个绊脚石。我试过谷歌的答案,但我不太确定我的措词是什么,我需要的权利。我的代码看起来像这样。更改变量的变量
<?PHP
$exchange = $_POST['exchange'];
$estimate = $_POST['estimate'];
$wp = $_POST['wp'];
$label1 = $_POST['name3'];
$result1 = $_POST['fb1'];
$result2 = $_POST['fb2'];
$username = "-----";
$password = "-----";
$hostname = "-----";
$con = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL");
$selected = mysql_select_db("-----", $con) or die("Could not select examples");
$query = "UPDATE btsec SET Status='$result1', TM='result2' WHERE Exchange='$exchange' AND Estimate='$estimate' AND WP='$label1' AND SectionID='$label1'";
if (!mysql_query($query,$con))
{
die('Error: ' . mysql_error($con));
}
}
echo "Sections updated for WP's $wp on $estimate on the $exchange Exchange!";
mysql_close($con);
?>
我需要做的是循环查询,但每次更改变量的内容。
$label1 = $_POST['name3']; needs to become $label1 = $_POST['name6'];
$result1 = $_POST['fb1']; needs to become $result1 = $_POST['fb10'];
$result1 = $_POST['fb2']; needs to become $result1 = $_POST['fb11'];
正如我所说的谷歌是无法弥补我的不好的措辞。
是否有任何规则选择这些索引,或者你只是随机挑选它们? –
@YUNOWORK窗体标签name3在表单的每个部分增加3,fb1增加9.它贯穿整个 –
您可能会发现将输入字段用作数组更容易:name =“name [ 3]“','name =”name [6]“','name =”fb [1]“','name =”fb [10]“'等等 - 然后你可以做foreach $ _POST ['name'] as $ index => $ name)'... – MichaelRushton