无法从数据库回显到表单

时间:2017-01-22 10:33:40

标签: php mysql sql forms

所以我想从我的数据库中回显一个特定的值,但它并没有。我想将这个值反映成这样的文本形式:

<h6 class="brand-before" align="center"><small>Konyhakész fa</small></h6><br>
<input type="text" name="konyha" size="18" align="center" value="<?php echo $konyha; ?>" />

这就是我连接到MySQL的方式:

<?php
mysql_connect("localhost", "koristuzep", "***") or die("Kapcsolódás az adatbázishoz sikertelen.");
mysql_select_db("koristuzep")or die("Kapcsolódás az adatbázishoz sikertelen.");

$konyha = mysql_query("SELECT * FROM $arak WHERE ID=3")
?>  

1 个答案:

答案 0 :(得分:0)

你应该首先从$ konyha中获取结果,如本例所示

   <?php
       $servername = "localhost";
       $username = "username";
       $password = "password";
       $dbname = "myDB";

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

     $sql = "SELECT id, firstname, lastname FROM MyGuests";
     $result = $conn->query($sql);

    if ($result->num_rows > 0) {
        // output data of each row
      while($row = $result->fetch_assoc()) {
    echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " .$row["lastname"]. "<br>";
}
  } else {
echo "0 results";
  }
  $conn->close();
 ?>