gpt4 book ai didi

php - WordPress - 选择特定页面上的查询

转载 作者:行者123 更新时间:2023-11-29 21:39:23 25 4
gpt4 key购买 nike

我想在特定页面中选择查询。我在数据库中创建了表:

enter image description here

首先,我添加了 phpexec在页面上使用 PHP 的插件。然后,我测试了 Select 查询,结果没问题。最后,我想创建用于检查序列号的表单。这是我的代码:

<html>
<head>
<title></title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"><br><br>
Serial Number: <input type="Text" Name="Num1"><p>
<input type="Submit" value="Calculate">
</form>
<phpcode>
<?php
if (count($_POST) > 0 && isset($_POST["Num1"])
{
$servername = "localhost";
$username = "******";
$password = "*******";
$dbname = "******";
$serialNum = $_POST["Num1"];

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT Install FROM SN WHERE serial = $serialNum";
$result = $conn->query($sql);

if ($result->num_rows > 0) {

while($row = $result->fetch_assoc()) {
echo "id: " . $row["Install"];
}
} else {
echo "no result";
}
$conn->close();
}
?>
</phpcode>
</body>
</html>

实际输出是:

enter image description here

如何解决这个问题?

最佳答案

你的表格坏了...试试这个方法

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<p>Serial Number: <input type="Text" Name="Num1" value=""></p>
<input type="Submit" value="Calculate">
</form>

关于php - WordPress - 选择特定页面上的查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34662027/

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