Json response with Postman:
[
{
"id": "1",
"correo": "[email protected]",
"clave": "123456",
"numero": "+1 5412-2154"
}
]
Buton login:
try
{
ASCIIEncoding encoding = new ASCIIEncoding();
string postData = "correo='" + txtuser.Text + "' and clave='" + txtpassword.Text + "'";
byte[] DataBindings = encoding.GetBytes(postData);
WebRequest request = WebRequest.Create("http://website.com/usuario_login.php");
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = DataBindings.Length;
Stream stream = request.GetRequestStream();
stream.Write(DataBindings, 0, DataBindings.Length);
stream.Close();
WebResponse response = request.GetResponse();
stream = response.GetResponseStream();
StreamReader sr = new StreamReader(stream);
String Mensaje = sr.ReadToEnd();
if (Mensaje.Equals("null"))
{
lblError.Text = "Al parecer los datos no coinciden";
btnlogin.Text = "Iniciar Sesión";
}
else
{
voiceUrl admin = new voiceUrl(Mensaje);
this.Hide();
admin.ShowDialog();
this.Close();
}
sr.Close();
stream.Close();
}
catch (Exception ex)
{
MessageBox.Show("Error : " + ex.Message);
}
Error:
Fatal error : Call to a member function fetch_assoc () on a non-object in
Php query file:
if($_SERVER["REQUEST_METHOD"]=="POST"){
include('conexion.php');
header('Content-Type: application/json; charset=utf8');
$correo= $_POST['correo'];
$clave= $_POST['clave'];
$result = mysqli_query($con,"SELECT * FROM usuarios WHERE correo='$correo' and clave='$clave'") or mysqli_error($con);
while ($row = $result->fetch_assoc()) {
$arr[] = $row;
}
$json = json_encode($arr,JSON_UNESCAPED_UNICODE);
echo $json;
}
Does anyone know what is happening?