Ich bin so php bitte führen und machen es nicht duplizieren, weil ich nicht Lösung aus früheren solutions.My PHP-Code bekommenUndefinierter Indexfehler in PHP, obwohl ich es definiert habe. Warum?
unter<?php
if($_SERVER['REQUEST_METHOD']=='GET'){
$city = $_GET['city'];
$town = $_GET['town'];
//$skills=$_POST['skills'];
require_once('DbConnect.php');
//Creating sql query
$sql = "SELECT FROM employees where city='".$city."' and town='".$town."'";
//getting result
$r = mysqli_query($con,$sql);
//creating a blank array
$result = array();
//looping through all the records fetched
while($row = mysqli_fetch_array($r)){
//Pushing name and id in the blank array created
array_push($result,array(
"name"=>$row['name'],
"phone"=>$row['phone'],
"skills"=>$row['skills']
));
}
//Displaying the array in json format
echo json_encode(array('result'=>$result));
mysqli_close($con);
}
?>
ERROR gegeben
notice: Undefined index: Stadt in C: \ xampp \ htdocs \ getServices \ employeesInfo.php auf Linie 3
notice: Undefined index: Stadt in C: \ xampp \ htdocs \ getServices \ employeesInfo.php auf Linie 4
Warning: mysqli_fetch_array() erwartet 1 Parameter MySQLi_Result, boolean Bereichen gemäß c: 17 { "result" []} \ xampp \ htdocs \ getServices \ employeesInfo.php on line
Ändern Sie Ihre SQL-Abfrage in '$ sql =" SELECT * FROM Mitarbeiter ... " –
Wie lautet die URL oder das Formular? Sie sind offen für SQL-Injektionen, parametrisieren. Nur die Anfrage-Methode zu überprüfen ist nicht genug. – chris85
Abgesehen von den offensichtlichen SQL-Injection-Problemen, wenn in Ihrer URL keine get vars für Stadt oder Ort definiert sind, erhalten Sie diesen Fehler –