希望有人可以帮我解决这个“简单”问题。
我在从mysql数据库收集的表中有数据。我希望用户能够将“PRICE”列编辑为任何和所有行,然后按更新按钮,该按钮将数据发送到表并更新“PRICE”列中的所有行。
对于我的生活,我无法让数据库更新。我知道它必须是我所缺少的东西。它必须是如此简单的事情,这是可笑的。
请帮帮忙?
if (isset($_POST['update']))
{
echo '<pre>';
print_r($_POST);
echo '</pre>';
if (is_array($ID))
{
foreach($_POST['hidden'] AS $ID)
{
echo "ID is: " . $ID . "</br>";
echo "Price is: " . $pricing . "</br>";
$ID = mysqli_real_escape_string($conn, $_POST['hidden'][$ID]);
$pricing = mysqli_real_escape_string($conn, $_POST['price'][$ID]);
$updateQuery = 'UPDATE `bathroom_price` SET `price` ="' . $pricing . '" WHERE `ID`=' . $ID;
mysqli_query($conn, $updateQuery) or die(mysql_error());
}
}
}
?>
</head>
<?php
mysqli_select_db($conn, "table_name");
?>
<div class="row center-xs">
<div style="margin-top:100px;" class="col-xs-12 col-sm-12 col-md-12 col-lg-8">
<div class="box">
<form method=POST>
<h1>Price List for Bathroom Form</h1>
<table>
<?
$secondSQL = "SELECT question, question_ID, ID, form_ID, form_name FROM bathroom_price GROUP BY question_ID, form_name ORDER BY ID ";
$result1 = mysqli_query($conn, $secondSQL);
while ($row = mysqli_fetch_assoc($result1))
{
$question_ID = $row['question_ID'];
$question = $row['question'];
$formID = $row['form_ID'];
$form_name = $row['form_name'];
?>
<input type=hidden value="<? echo $question_ID ?>">
<tr class='questionHeading'>
<td colspan='3'>
<h2><? echo $question ?></h2>
<h3>Questions for the <? echo $form_name ?> Form</h3></td>
</tr>
<tr>
<th>Options:</th>
<th>Price:</th>
<th>Update:</th>
</tr>
<?
$thirdSQL = "SELECT question_ID, options, price, ID FROM bathroom_price WHERE question_ID = $question_ID";
$replies = mysqli_query($conn, $thirdSQL);
while ($rows = mysqli_fetch_assoc($replies))
{
$price = $rows['price'];
$options = $rows['options'];
$ID = $rows['ID'];
?>
<input type=hidden name="hidden[]<?echo $ID ?>" value="<?echo $ID ?>" />
<input type=hidden value="<? echo $question_ID ?> " />
<tr>
<td style='width:60%;'>
<input readonly type=text value="<? echo $options ?>">
</td>
<td style='width:10%;'>
<input type=text name="price[]<?echo $ID ?>" value="<?echo $price ?>">
</td>
</tr>
<?}?>
<?}?>
</table>
<div class="start-xs" style="margin: 0 0 50px 0;">
<button type=submit name="update" class="admin-style" value="Update Price Form">
<i class="fa fa-save"></i> Update Price Form
</button>
</div>
</form>
</div>
</div>
</div>
</body>
</html>
<?php mysqli_close($conn);?>
答案 0 :(得分:0)
也许这是一个问题:
<input type=hidden name="hidden[]<?echo $ID ?>" value="<?echo $ID ?>" />
您的输入名称是“隐藏[] 1”等。