【发布时间】:2018-10-02 13:14:34
【问题描述】:
我正在尝试从页面中的数据库表加载数据。
我在下面报告的这个是一个示范性例子,解释我想如何实现它...... 实际上,我们正在谈论数据库的 100 个字段和 1000 个并传递表的代码行...
<?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);
}
$idCantiere = $_GET['idCantiere'];
$sql1 = "SELECT * FROM Cantiere WHERE idCantiere = '$idCantiere'";
$result = mysqli_query($sql1, $conn);
$details = mysqli_fetch_array($result);
$savedNomeCantiere = $details["nomeCantiere"];
$savedCodiceCommessa = $details["codiceCommessa"];
$savedIndirizzoCantiere = $details["indirizzoCantiere"];
var_dump($details);
$result1 = $conn->query($sql1);
echo($nomeCantiere);
?>
<html>
<head>
</head>
<body>
<table width="300" border="0">
<tr>
<td>Name</td>
<td><input type="text" name="savedNomeCantiere" style="text-align:right" value="<?php echo $savedNomeCantiere; ?>" /></td>
</tr>
<tr>
<td>Cost</td>
<td><input type="text" name="savedCodiceCommessa" style="text-align:right" value="<?php echo $savedCodiceCommessa; ?>" /></td>
</tr>
<tr>
<td>Cost</td>
<td><input type="text" name="savedIndirizzoCantiere" style="text-align:right" value="<?php echo $savedIndirizzoCantiere; ?>" /></td>
</tr>
</table>
<br/>
</body>
</html>
我尝试过在文本框的“值”中添加“回声”的这种上传类型,但它不起作用。
此行用于通过页面重定向导出“id”。
$idCantiere = $_GET['idCantiere'];
如果我想尝试 var_dump($details) 它返回 NULL
【问题讨论】:
-
您不能混合使用 mysqli 和 mysql API。将所有内容切换到 mysqli。
-
@aynber 哪里对不起?
-
您的查询和获取都使用 mysql_* 而不是 mysqli
-
你能用当前代码edit你的帖子吗?要么它仍然不起作用,要么没有结果。
标签: php html mysql database load