簡體   English   中英

如何在中顯示價值 <select>從MySQL數據庫使用PHP?

[英]How to display value in <select> from mysql db using php?

我在php中有一個表單,需要在其中使用php從數據庫(phpmyadmin)中選擇值。 當我添加我的代碼時,它不起作用。 任何人都可以檢查此代碼嗎?

    <form role="form" action="test.php" enctype="multipart/form-data" method="post" accept-charset="utf-8">
    <div class="form-group">
      <label for="name">Name:</label>
      <input type="text" class="form-control" name="name" id="name" placeholder="Enter Category Name">
    </div>
    <div class="form-group">
      <label for="code">Code:</label>
       <select>
      <?php 
/* change character set to utf8 */
        if (!mysqli_set_charset($conn, "utf8")) {
            printf("Error loading character set utf8: %s\n", mysqli_error($conn));
            exit();
        } else {
            $rslt=mysqli_query($con,"SELECT * from category") or die(mysqli_error($conn));
        }

        while ($row = mysql_fetch_array($rslt)){
              echo $row;
                echo "<option value=\"owner1\">" . $row['code'] . "</option>";
        }
    ?>
        </select>
    </div>
     <div class="form-group">
      <label for="rank">Rank:</label>
      <input type="text" class="form-control" name="rank" id="rank" placeholder="Enter Category Rank ">
    </div>
    <div class="form-group">
      <label for="tag">Tags:</label>
      <input type="text" class="form-control" name="tag" id="tag" placeholder="Enter Category tag ">
    </div>

    <button type="submit" class="btn btn-default">Done</button>
  </form>

從評論前進,這是需要的:

代替:

while($row = mysql_fetch_array($sql)){

本來應該:

while($row = mysqli_fetch_assoc($rslt){

注意:還有一些其他警告。 但這只是在您關心的情況下。 干杯

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM