【问题标题】:Warning: mysqli::query(): Couldn't fetch mysqli in . How can I solve it? [duplicate]警告:mysqli::query(): 无法在 .我该如何解决? [复制]
【发布时间】:2016-08-29 22:01:35
【问题描述】:

我有这段代码,但出现以下错误:

警告:mysqli::query(): 无法在第 299 行的 C:\xampp\htdocs\pliroforiaka\grammateiakos_upallilos.php 中获取 mysqli

注意:尝试在 C:\xampp\htdocs\pliroforiaka\grammateiakos_upallilos.php 第 301 行获取非对象的属性

警告:mysqli::close(): 无法在第 317 行的 C:\xampp\htdocs\pliroforiaka\grammateiakos_upallilos.php 中获取 mysqli

<table name="table5" id="table5" width="941" border="1" cellspacing="0" cellpadding="3" align="center">
<form name="form5" class="form5" id="form5" action="stoixeiarantevou.php" method="post"> 
<td>
<?php
$sql = "SELECT username FROM giatros";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
?>
<div id="doc">
<select name="Doctor">
<?php
// output data of each row
while($row = $result->fetch_assoc()) {
?>
    <option value="<?php echo $row['Doctor']; ?>"><?php echo $row['username'];?>        </option>
<?php
}
?>
</select>
</div>
<?php
 }
$conn->close();
   ?>
 Ημερομηνία: <input type="text" id="Hmeromhnia" name="Hmeromhnia" required>   <br>
 Ώρα: <input type="text" id="Wra" name="Wra" required><br>
 <input type="button" value="Δημιουργία" id="btnsubmit" onclick="submitForm3()" required>
 </td>
 </form>
 </table>
 <script>
  function submitForm3() {
   // Get the first form with the name
   // Hopefully there is only one, but there are more, select the correct index
   var frm = document.getElementsByName('form5')[0];
   frm.submit(); // Submit
   frm.reset();  // Reset
   alert("Τα στοιχεία σας ανανεώθηκαν επιτυχώς");
   return false; // Prevent page refresh

     }

   </script>
   </td>
   </tr>

【问题讨论】:

  • 您的 mysqli 连接似乎有问题。检查那里
  • 这可能是由于:a) 与数据库的连接不正确,或关闭过早。查看错误,它看起来是 A。您可以发布您的连接代码吗?

标签: php mysqli


【解决方案1】:

这里的问题是你提前关闭了数据库连接。 删除这一行

$conn -> 关闭();

【讨论】:

    猜你喜欢
    • 2014-08-14
    • 2017-02-28
    • 2019-01-09
    • 2018-05-31
    • 2020-02-07
    • 2020-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多