2017-02-23 2 views
1
Warnung

Ich habe in meiner PHP-Datei folgende Fehlermeldung:mysqli_fetch_array() erwartet 1 Parameter MySQLi_Result wird

Notice: Undefined index: q in C: \ xampp \ htdocs \ medphil \ getpatient.php on line 22

Warnung: mysqli_fetch_array() erwartet 1 Parameter in C MySQLi_Result, boolean gegeben werden: \ xampp \ htdocs \ medphil \ getpatient.php on line 46

dies ist mein Code bitte helfen Sie mir zu löse dieses

<!DOCTYPE html> 
<html> 
<head> 
<style> 
table { 
    width: 100%; 
    border-collapse: collapse; 
} 

table, td, th { 
    border: 1px solid black; 
    padding: 5px; 
} 

th {text-align: left;} 
</style> 
</head> 
<body> 

<?php 

$q = intval($_GET['q']); 



$con = mysqli_connect('localhost','root','','medphil'); 
if (!$con) { 
    die('Could not connect: ' . mysqli_error($con)); 
} 

mysqli_select_db($con, "medphil"); 
$sql="SELECT * FROM patients WHERE id = '".$q."'"; 
$result = mysqli_query($con,$sql); 

echo "<table> 
<tr> 
<th>Firstname</th> 
<th>Lastname</th> 
<th>username</th> 
<th>password</th> 
<th>dateofbirth</th> 
<th>email</th> 
<th>Patientaddress</th> 
<th>LastLDNId</th> 
</tr>"; 
while($row = mysqli_fetch_array($result,true)) { 
    echo "<tr>"; 
    echo "<td>" . $row['FirstName'] . "</td>"; 
    echo "<td>" . $row['LastName'] . "</td>"; 
    echo "<td>" . $row['username'] . "</td>"; 
    echo "<td>" . $row['password'] . "</td>"; 
    echo "<td>" . $row['dateofbirth'] . "</td>"; 
    echo "<td>" . $row['email'] . "</td>"; 
    echo "<td>" . $row['Patientaddress'] . "</td>"; 
    echo "<td>" . $row['LastLDNId'] . "</td>"; 
    echo "</tr>"; 
} 
echo "</table>"; 
mysqli_close($con); 
?> 
</body> 
</html> 
+0

Wie Ihre URL aussieht? Gibt es einen Param 'q'? – C2486

+0

'Hinweis: Undefinierter Index: q' sollte Ihnen alles sagen, was Sie wissen müssen. Warum ist 'q' nicht gesetzt? – chris85

Antwort

-1

@afra raheem
Sie erhalten diesen Fehler, da mysqli_fetch_array() erforderlich Mysqli variabel und in der Abfrage Ergebnisvariable führen empty oder boolean false ist.

Sie erhalten Ergebnisvariable empty oder boolean false so müssen Sie id Feldwert in Abfrage zu übergeben, während Sie $q Variable sind vorbei = $_GET['q'], die nicht gesetzt ist, bis Sie YOURFILE.php?q=YOUR VALUE passieren nicht, wenn Sie diesen Wert in URL übergeben oder sie setzen Programmatisch dann funktioniert Ihr Code gut.

0

@afra raheem ist dies, weil Ihr $ _GET [ 'q'] gesetzt ist nicht so einfach einen Zustand mit Ihrem PHP-Code machen wie unten:

<?php 
    $q = isset($_GET['q']) ? intval($_GET['q']) : ""; 

    if(!empty($q) && is_int($q)){ 
     $con = mysqli_connect('localhost','root','','medphil'); 
     if (!$con) { 
      die('Could not connect: ' . mysqli_error($con)); 
     } 

     mysqli_select_db($con, "medphil"); 
     $sql="SELECT * FROM patients WHERE id = '".$q."'"; 
     $result = mysqli_query($con,$sql); 

     echo "<table> 
     <tr> 
     <th>Firstname</th> 
     <th>Lastname</th> 
     <th>username</th> 
     <th>password</th> 
     <th>dateofbirth</th> 
     <th>email</th> 
     <th>Patientaddress</th> 
     <th>LastLDNId</th> 
     </tr>"; 
     while($row = mysqli_fetch_array($result,true)) { 
      echo "<tr>"; 
      echo "<td>" . $row['FirstName'] . "</td>"; 
      echo "<td>" . $row['LastName'] . "</td>"; 
      echo "<td>" . $row['username'] . "</td>"; 
      echo "<td>" . $row['password'] . "</td>"; 
      echo "<td>" . $row['dateofbirth'] . "</td>"; 
      echo "<td>" . $row['email'] . "</td>"; 
      echo "<td>" . $row['Patientaddress'] . "</td>"; 
      echo "<td>" . $row['LastLDNId'] . "</td>"; 
      echo "</tr>"; 
     } 
     echo "</table>"; 
     mysqli_close($con); 
    } 
    else{ 
     echo "q can not be empty"; 
    } 
?> 
Verwandte Themen