i new php please guide , don't make duplicate because can't solution previous solutions.my php code given below
<?php if($_server['request_method']=='get'){ $city = $_get['city']; $town = $_get['town']; //$skills=$_post['skills']; require_once('dbconnect.php'); //creating sql query $sql = "select employees city='".$city."' , town='".$town."'"; //getting result $r = mysqli_query($con,$sql); //creating blank array $result = array(); //looping through records fetched while($row = mysqli_fetch_array($r)){ //pushing name , id in blank array created array_push($result,array( "name"=>$row['name'], "phone"=>$row['phone'], "skills"=>$row['skills'] )); } //displaying array in json format echo json_encode(array('result'=>$result)); mysqli_close($con); } ?>
error
notice: undefined index: city in c:\xampp\htdocs\getservices\employeesinfo.php on line 3
notice: undefined index: town in c:\xampp\htdocs\getservices\employeesinfo.php on line 4
warning: mysqli_fetch_array() expects parameter 1 mysqli_result, boolean given in c:\xampp\htdocs\getservices\employeesinfo.php on line 17 {"result":[]}
you need select 1 or more columns, example doing select all select * from..
, query this
$sql = "select * employees city='".$city."' , town='".$town."'";
update_code:
<?php if($_server['request_method']=='get' && !empty($_get['city']) && !empty($_get['town'])){ $city = $_get['city']; $town = $_get['town']; //$skills=$_post['skills']; require_once('dbconnect.php'); //creating sql query $sql = "select * employees city='".$city."' , town='".$town."'"; //getting result $r = mysqli_query($con,$sql); //creating blank array $result = array(); //looping through records fetched while($row = mysqli_fetch_array($r)){ //pushing name , id in blank array created array_push($result,array( "name"=>$row['name'], "phone"=>$row['phone'], "skills"=>$row['skills'] )); } //displaying array in json format echo json_encode(array('result'=>$result)); mysqli_close($con); } else{ $message = " fill details first"; } if(isset($message) && !empty($message) ){ echo "$message"; } ?>
Comments
Post a Comment