也许标题混淆了。但我有这样的案例,
我有一个包含一些输入文本(文本框)的表单。但是这个输入取决于我的数据库。
<label class="strong"><?php echo $rowexp['mexpense_name']; ?></label>
<input type="text" class="span4" placeholder="Expense <?php echo $rowexp['mexpense_name']; ?>" name="" />
这是我输入文本的数据库:
tbl_mexpensive -> mexpensive_id, mexpensive_name
tbl_expensive -> expensive id, expensive_year
tbl_texpensive -> mexpensive_id, expensive_id
因此,文本字段的数量与tbl_mexpensive的数据相同,POST页面将设置为tbl_texpensive。
例如,如果mexpensive得到3值,那么:
[textbox1] [textbox2] [textbox3]
If i click submit
It return to POST page and get the value each of the textbox
BUT the query is like this: insert into texpensive (exp_id, mexp_id) VALUE (exp_id, XXX)
从上面,我的问题是,如何在POST页面(XXX)获取值?我的意思是,我应该给输入文本一个名字?我试过一个阵列,但它不能正常工作。我尝试将其命名为表值,但仍然没有结果,因为它是一个动态文本框。
抱歉我的英语不好。
- 编辑
我的帖子页
$asal = $_POST['asal'];
$unit = $_POST['unit'];
$tahun = $_POST['tahun'];
$querydata = mysql_query("SELECT * FROM m_mainexpense WHERE mexpense_status=1");
$last = mysql_query("SELECT * FROM t_expense");
$getlast = mysql_fetch_array($last);
$nom = (int)$getlast['expense_id'] + 1;
while($rowdata = mysql_fetch_array($querydata))
{
if(isset($_POST[mexpense_name]))
{
//actually don't know what to do in here
$arr = $_POST[mexpense_name];
$query = "INSERT INTO t_expense (texp_mext, texp_exp) VALUES ('$arr','$nom')";
}
}
$query = "INSERT INTO m_expense(expense_unit, expense_school, expense_year, expense_type, expense_status)
VALUES ('$unit', '$asal', '$tahun', 1)";
if(mysql_query($query))
{
echo "<script>
alert('Penambahan Data Sukses');
window.location.href='return_index.php';
</script>";
echo '<noscript>
Please Enable Your JavaScript.
<a href="welcome.php">Main Menu</a>
</noscript>';
die();
}
答案 0 :(得分:0)
使用key($ array)并通过foreach函数获取值。并将其返回数据库。最后它解决了....