gpt4 book ai didi

PHP MySQL UPDATE 查询未从文本框中发布值

转载 作者:行者123 更新时间:2023-11-29 19:05:34 26 4
gpt4 key购买 nike

我有一个表单,其中包含从数据库填充的选择列表。执行查询时,会返回一条成功消息,但数据库不会更新。

表格如下:

 <form id="formPrice">
<?php
$conn = new mysqli('localhost', 'something', 'something', 'something')
or die ('Cannot connect to db');
$result = $conn->query("SELECT PlotNumber FROM Developments WHERE Development = 'GREENGRAVES' AND Price = 'BOOKED'");
echo "<select name='plot_update'>";
while ($row = $result->fetch_assoc()) {
echo "<option value=\"Plot\">" . $row['PlotNumber'] . "
</option>";
}
echo "</select>";
?>
<input name="price" type="text" id="price">
<input name="update" type="submit" class="update_price">
</form>

这是ajax请求:

 $('.update_price').click(function() {
var FormData = $('form').serialize();
$.ajax({
type: "POST",
url: '../php/update_price.php',
data : FormData,
success:function(html){
document.getElementById("result_two").innerHTML=html;
}
});
return false;
});

这是 php

$conn = new mysqli($servername, $username, $password, $dbname);

if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$price = $_POST['price'];
$plot = $_POST['plot'];
$sql = "UPDATE Developments SET Price = '".$price."' WHERE PlotNumber = '".$plot."' ";

if ($conn->query($sql) === TRUE) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . $conn->error;
}

$conn->close();

页面在结果 div 中显示“记录更新成功”,但数据库条目保持不变。有什么想法吗?我被难住了。

最佳答案

错误似乎出在前端表单中的这一行:

echo "<option value=\"Plot\">" . $row['PlotNumber'] . "</option>";

当我更改为:

echo "<option>" . $row['PlotNumber'] . "</option>";

成功了!

关于PHP MySQL UPDATE 查询未从文本框中发布值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43542028/

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