【发布时间】:2018-10-03 12:52:40
【问题描述】:
我需要知道您是否可以执行此功能...我有一个数据库,其中包含一个接受 0 或 1 值的“布尔”字段并且我有一个 HTML 页面,其中有一个带有值 Ok 或 No 的单选按钮我必须能够在单选按钮中加载布尔值,因此如果在数据库中,布尔变量在 HTML 页面上为 1(在执行 SELECT 之后),如果在数据库中布尔变量在 HTML 上为 0,则单选按钮将具有 OK 值页面(执行 SELECT 后)radioButton 将没有值
这是我尝试的代码:
<?php
$servername = "localhost";
$username = "progettocantiere";
$password = "";
$dbname = "my_progettocantiere";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$idAffidataria = $_GET['idAffidataria'];
$sql1 = "SELECT * FROM Affidataria WHERE idAffidataria = '{$idAffidataria}'";
$result = $conn->query($sql1);
$details = $result->fetch_array();
$savedNomeCantiere = $details["nomeCantiere"];
$savedAddettoSicurezza = $details["addettoSicurezza"];
$savedMailAffidataria = $details["mailAffidataria"];
$savedContrattoDiAppalto = $details["contrattoDiAppalto"]; // <--- BOOLEAN <----
$result1 = $conn->query($sql1);
echo($nomeCantiere);
?>
<html>
<body>
<table>
<tr>
<td colspan="2" bgcolor="#CDECFD" style="font-weight: bold">Cantiere</td>
<td colspan="4" bgcolor="#CDECFD"><input type="text" class="form-control" style="width: 100%;" name="cantiereAffidataria" id="cantiereAffidataria" value="<?php echo $savedNomeCantiere; ?>"/> </td>
</tr>
<tr>
<td colspan="2" bgcolor="#CDECFD" style="font-weight: bold">ContrattoDiAppalto</td>
<td bgcolor="#B35556"><form action="">
OK <input type="radio" name="contrattoDiAppalto" id="contrattoDiAppalto" value="<?php echo $savedContrattoDiAppalto; ?>" onchange="color(this)" /> <BR>
NO <input type="radio" name="contrattoDiAppalto" id="contrattoDiAppalto" value="<?php echo $savedContrattoDiAppalto; ?>" onchange="color(this)" checked/>
</form></td>
</tr>
</table>
换句话说,我必须能够根据数据库上的 SELECT 提供的数据来更改单选按钮
我试图通过<?php echo $savedContrattoDiAppalto; ?>" 赋予它价值,但我怀疑它是否正确.. 我的想法已经不多了.. 有人可以帮助我吗?
【问题讨论】:
-
您不能在 DOM 中拥有相同的
id。所有id必须是唯一的。将两个选项的radio设置为相同的value将导致意外行为。
标签: javascript php html mysql database