gpt4 book ai didi

php - 更新数据库表中所有行的 1 列

转载 作者:行者123 更新时间:2023-11-29 20:09:02 25 4
gpt4 key购买 nike

希望有人能帮助我解决这个“简单”的问题。

我的表中有从 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);?>

最佳答案

也许这是一个问题:

<input type=hidden name="hidden[]<?echo $ID ?>" value="<?echo $ID ?>" />

您输入的名称是“hidden[]1”等。

关于php - 更新数据库表中所有行的 1 列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40251046/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com