【发布时间】:2015-03-29 09:01:48
【问题描述】:
我的系统有问题。我需要将文本框相乘,然后在 mysql 中使用串联插入一列。我在我的系统中使用 PHP。具体来说,我的源代码是 ff:
这是索引
<html>
<head>
<title>Sample Text</title>
</head>
<body>
<form action="phpfunctionshandle.php" method="post" name="phpfunctionshandle">
<input type="number" name="text" />
<button type="submit" name="submit"value="Register">Submit</button>
<button type="reset"value="cancel">Cancel</button>
<input type="hidden" name="submitted" value="TRUE" >
</form>
</body>
</html>
这是索引的句柄
<html>
<head>
<title>Sample</title>
</head>
<body>
<form action="handlefinal" method="post" enctype="multipart/form-data" name="phpfunctionshandle">
<?php
include('config.php');
$text =$_POST['text'];
for ($x = 1; $x <= $text; $x++) { // I use for loop to multiple text box
echo '<input type="text" name="sample value=""/>';
}
?>
<button type="submit" name="submit"value="Register" class="btn btn-primary">Submit</button>
<button type="reset"value="cancel" class="btn btn-success">Cancel</button>
<input type="hidden" name="submitted" value="TRUE" >
</form>
<Form name="handlefinal">
<?php
include('config.php');
$sample=$_POST['sample"'.$text.'"'];
$query = "INSERT INTO sample (text) VALUES ('$sample')";
$result = mysql_query($query) or die(mysql_error());
echo'success';
?>
</form>
</body>
</html>
我使用 for 循环根据我在索引上输入的内容来多个文本框。比如我在index.php的输入类型号中输入3,文本框会乘以3。我想要的结果是查询3相乘的文本框。 如果我在第一个文本框中输入 sample1,在第二个文本框中输入 sample2,在第三个文本框中输入 sample3。列文本中所需的数据库输出应为 样品 1、样品 2、样品 3。我试试这个,但结果是文本框的最后一个值只插入到数据库中。总之只有sample3。我不知道如何查询以及如何解决这个问题。有什么建议么?很抱歉发布我所有的源代码。感谢您的耐心等待。
【问题讨论】:
-
您在此处缺少引用
":echo '<input type="text" name="sample value=""/>';。应该是echo '<input type="text" name="sample" value=""/>';