dsgawmla208057 2019-08-12 22:06
浏览 78

我怎样才能使用php从主键字段填充我的文本输入onBlur的SQL数据库?

I have gotten my form to search my SQL db table and return a row:

<?php
            if(isset($_POST["Bearch"])){
                    $sql = "SELECT * FROM $table WHERE Name='$Name'";
                    $result = $conn->query($sql);
                    if ($result->num_rows > 0) {
// output data of each row
                    while($row = $result->fetch_assoc()) {
                    echo "<tr>";
                    echo "<th>".$row["Name"]."<th>". $row["MAC"]."<th>". $row["Own"]."<th>". $row["Type"]."<th>". $row["Model"]."<th>". $row["OS"]."<th>". $row["Office"]."<th>". $row["Us"]."<th>". $row["Building"]."<th>". $row["BKP"]."<th>". $row["WSUS"]."<th>". $row["SMC"]."<th>". $row["SSO"]."<th>". $row["CBS"]."<th>". $row["Decom"];
                    echo "</tr>";
                        }
                } else {
                    echo "0 results";
                        }}
     ?>

However, I would like the form to fill in the input text boxes instead. Does anyone know how I would go about this?

I have tried several different ways of getting the value to display the fields but the result is always the same; The fields that I entered in to the text boxes stays instead of changing to what the db has for those fields.

  Device Name: <input type="text" id="myInput" required="required" name="Name" autofocus="true" onBlur="
// I've tried this as a function as well.
<?php $sql="SELECT * FROM $table WHERE Name = $Name;";
        $result = $conn->query($sql);
                if ($result->num_rows > 0) {
                while($row = $result->fetch_assoc()) {
                    $Name=$row["Name"];
                                        $MAC=$row["MAC"];
                    $Own=$row["Own"];
                    $Type=$row["Type"];
                    $Model=$row["Model"];
                    $OS=$row["OS"];
                    $Off=$row["Office"];
                    $Us=$row["Us"];
                    $_POST["Build"]=$row["Building"];
                    $_POST["BKP"]=$row["BKP"];
                    $_POST["WSUS"]=$row["WSUS"];
                    $_POST["SMC"]=$row["SMC"];
                    $_POST["SSO"]=$row["SSO"];
                    $_POST["CBS"]=$row["CBS"];
                    $_POST["Decom"]=$row["Decom"];
                }
                };?>" value=<?php echo $Name ?>>
  MAC Address: <input type="text" id="myInput" name="MAC" value="<?php echo $_SESSION["MAC"]; ?>">
  Owner or Location: <input type="text" name="Own" value="<?php echo htmlspecialchars($Own); ?>">

I am expecting the text boxes to display their respective fields from the database, onBlur from the "Name" field, but nothing (no text appearing in the text box) seems to happen.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 数学的三元一次方程求解
    • ¥20 iqoo11 如何下载安装工程模式
    • ¥15 本题的答案是不是有问题
    • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
    • ¥15 C++使用Gunplot
    • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
    • ¥15 matlab数字图像处理频率域滤波
    • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
    • ¥15 ELGamal和paillier计算效率谁快?
    • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题