1 回答
TA贡献1828条经验 获得超4个赞
我有包含设置点的输入文本框,我在数据库中的表具有默认值但需要如果我更改了文本框中的设置点将更新数据库表中的值,而无需单击按钮!
这是 HTML 代码:
<input class="tempSet" id="ACSet" type="text" value="35">
和 PHP 代码,但无法将文本框与 PHP 连接以选择新值:
<?php
$DATABASE_HOST = 'localhost';
$DATABASE_USER = 'user';
$DATABASE_PASS = 'pass';
$DATABASE_NAME = 'name';
// Try and connect using the info above.
$db = mysqli_connect($DATABASE_HOST, $DATABASE_USER, $DATABASE_PASS,
$DATABASE_NAME);
if (!$db){
die("Connection Failed: ". mysqli_connect_error());
}
$db_update = "UPDATE temp_setpoint SET set_point='??' WHERE id=1";
$result = mysqli_query($db, $db_update);
?>
文件.php
<?php
$DATABASE_HOST = 'localhost';
$DATABASE_USER = 'user';
$DATABASE_PASS = 'pass';
$DATABASE_NAME = 'name';
// Try and connect using the info above.
$db = mysqli_connect($DATABASE_HOST, $DATABASE_USER, $DATABASE_PASS, $DATABASE_NAME);
if (!$db) {
die("Connection Failed: " . mysqli_connect_error());
}
$data = array();
$acset = intval($_POST['acset']) ?? null; // value from form
$db_update = "UPDATE temp_setpoint SET set_point= ? WHERE id=1";
$stmt = $db->prepare($db_update);
$stmt->bind_param("i", $acset);
if ($stmt->execute()) {
$data = array(
"status" => 'success',
'message' => "Data updated sucess"
);
} else {
$data = array(
"status" => "fail",
'message' => "Updated fail, please try again later"
);
error_log($stmt->error);
}
echo json_encode($data);
?>
- 1 回答
- 0 关注
- 122 浏览
添加回答
举报