0

I have this code and i am getting these errors:

Warning: mysqli::query(): Couldn't fetch mysqli in C:\xampp\htdocs\pliroforiaka\grammateiakos_upallilos.php on line 299

Notice: Trying to get property of non-object in C:\xampp\htdocs\pliroforiaka\grammateiakos_upallilos.php on line 301

Warning: mysqli::close(): Couldn't fetch mysqli in C:\xampp\htdocs\pliroforiaka\grammateiakos_upallilos.php on line 317

<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>

Dharman
  • 30,962
  • 25
  • 85
  • 135
Nikos Bounas
  • 11
  • 1
  • 5
  • It looks like you have problems with mysqli connection. Check there – nospor Aug 29 '16 at 22:06
  • http://stackoverflow.com/questions/19937880/mysqliquery-couldnt-fetch-mysqli –  Aug 29 '16 at 22:31
  • This would be due either to: a) Incorrect connection to the database, or closing too early. Looking at the errors, it would look to be A. Can you post your connection code? – Connor Gurney Aug 30 '16 at 03:32

1 Answers1

1

the problem here is that you have closed the database connection early. remove this line

$conn -> close();