繁体   English   中英

将从数据库中获取的列表中的值复制到文本框并使其可编辑

[英]copy the value inside a list which is fetched from database to a text box and make it editable

我有一个从数据库中获取和显示的项目列表。 它将显示为导航栏。 当我单击任何列表项时,我想将项的名称复制到文本框并使其可编辑,应该有一个选项可以删除和保存列表项的可编辑名称。

 <div id="nav">
            <input type="button" value="Add new" onclick="location.href = 'addindustry.php';">
            <?php
            $conn=get_dbconnect();
            $sql="select * from industry";
            $result=mysqli_query($conn,$sql);
            while($row=mysqli_fetch_assoc($result)){
             echo "<ul>";
             echo "<li>";
             echo "<a href='modifyindustry.php'>";
             echo $row['name'];
             echo "</a>";
             echo "</li>";
             echo "</ul>";
            }
            ?>
        </div>

这个 $row['name'] 将从数据库中获取 18 个行业名称

您需要一个页面来展示您的行业:

行业.php

<?php while ($row = mysqli_fetch_assoc($result)): ?>
    echo "<ul>";
    echo "<li>";
    echo "<a href='modifyindustry.php?id=<?php echo $row['id']; ?>'>";
    echo $row['name'];
    echo "</a>";
    echo "</li>";
    echo "</ul>";
<?php endwhile; ?>

还有一个页面来编辑您的数据:

修改industry.php

<?php $result = mysqli_query($mysqli, 'select * from industries where' .
    ' id=' . $_GET['id']); ?>
<form action="modifyindustry.php?id=<?php echo $row['name']; ?>" method="...">
<?php if ($row = mysqli_fetch_assoc($result)): ?>
    echo "<ul>";
    echo "<li>";
    echo "<input type='text' name='name' value='<?php echo $row['name']; ?>' />";
    echo $row['name'];
    echo "</li>";
    echo "</ul>";
<?php endif; ?>
</form>
  • 请注意, $_GET['id'] 有一个危险的漏洞。 那只是一个例子。 您需要为您的查询使用准备好的语句。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM