json - php web service method post -
hi have php web return json data usin json!encode when change post return null
<?php header('content-type: application/json; charset=utf-8'); include('settings.php'); mysql_connect($host,$user,$password); mysql_select_db($base); mysql_query('set character set utf8'); $login = $_get['login']; $password = $_get['password']; $req = "select * user username = '".$login."' , password = '".$password."'"; $sql=mysql_query($req); $nn=mysql_num_rows($sql); $items = array("items" => null); while ($data=mysql_fetch_array($sql)) { $items["items"][] = array( "id" => $data['id'], "username" => $data['username'], "password" => $data['password'], "nom_prenom" => $data['nom_prenom'], "nom_prenom_arabe" => $data['nom_prenom_arabe'], "specialite" => $data['specialite'], "specialite_arabe" => $data['specialite_arabe'], "adresse" => $data['adresse'], "adresse_arabe" => $data['adresse_arabe'], "telephone_cabinet" => $data['telephone_cabinet'], "gsm" => $data['gsm'], ); } echo json_encode($items,json_unescaped_unicode); ?>
it returns
{"items":[{"id":"2","username":"**","password":"*","nom_prenom":"****","nom_prenom_arabe":"مهذب عبد الصمد ","specialite":"pediatrie","specialite_arabe":"إختصاصي في الامراض النفسية و العصبية","adresse":"av tahar sfar imm .el baraka sousse 4000","adresse_arabe":" 4000 شارع طاهر سفر عمارة البركة سوسة","telephone_cabinet":"73698521","gsm":"25631478"}]}
but
$login = $_post['login']; $password = $_post['password'];
it return
{"items":null}
can explain me why :) thanks
because post invoke page has method , remplace post work expected.
another point it's discouraged use string concatenation when quering databases due security risk. use prepared statements instead.
Comments
Post a Comment