Я пытаюсь получить «Неверный пароль» из файла php, но он всегда вводит одно и то же, если. Другими словами, даже если я помещаю правильный адрес электронной почты и пароль, я всегда получаю «неправильный пароль или уведомление по электронной почте». Вот код из встроенного реагирования и из php (я тестировал код php с почтальоном, и он отлично работает).
<?php
include("Config.php");
$username = $_POST['username'];
$password = $_POST['password'];
$link = mysqli_connect("$HostName", "$HostUser", "$HostPass", "$DatabaseName");
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$check = mysqli_query($link,"SELECT mail FROM Usuarios WHERE `mail`= '$username' AND `contraseña`= '$password'");
$numrows = mysqli_num_rows($check);
if ($numrows == 0 )
{
//WRONG PASSWORD
die("Wrong Password");
}
else {
//login user
$row = mysqli_fetch_array($check);
$mail = $row['mail'];
$array = array('mail' => $mail);
$answer = json_encode($array);//"Login Done," . $mail;
echo($answer);
}
mysqli_close($link);
?><?php
function safe($variable)
{
$variable = addslashes(trim($variable));
return $variable;
}
?>import React from 'react';
import { StyleSheet, TouchableOpacity, TextInput, Text, View, Alert } from 'react-native';
import styles from './From.styles.js'
export default class Form extends React.Component
{
constructor(props) {
super(props)
this.state = {
UserEmail: '',
UserPassword: ''
}
}
UserLoginFunction = () =>{
const { UserEmail } = this.state ;
const { UserPassword } = this.state ;
fetch('https://andrianodna.000webhostapp.com/Login.php', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
username: UserEmail,
password: UserPassword
})
})
.then((response) => response.text())
.then((responseJson) => {
if (responseJson === 'Wrong Password')
{
//Alert.alert(responseJson);
Alert.alert('E-Mail o Contraseña equivocados')
//Then open Profile activity and send user email to profile activity.
}
else{
this.props.navigation.navigate('Router', { Email: UserEmail });
//Alert.alert(responseJson);
}
}).catch((error) => {
console.error(error);
});
}
render()
{
return (
<View style = {styles.container}>
<TextInput style = {styles.input}
placeholder = 'E-Mail'
onChangeText = {UserEmail => this.setState({UserEmail})}
placeholderTextColor = "rgba(0,0,0,0.3)"
keyboardType = "email-address"
underlineColorAndroid='rgba(0,0,0,0)'/>
<TextInput style = {styles.input}
placeholder = 'Contraseña'
onChangeText = {UserPassword => this.setState({UserPassword})}
placeholderTextColor = "rgba(0,0,0,0.3)"
underlineColorAndroid='rgba(0,0,0,0)'
secureTextEntry = {true} />
<TouchableOpacity onPress = {this.UserLoginFunction} style = {styles.Button}>
<Text style = {styles.buttonText}>{this.props.type}</Text>
</TouchableOpacity>
<TouchableOpacity style = {styles.Button2}>
<Text style = {styles.buttonText}>{this.props.type2}</Text>
</TouchableOpacity>
</View>
);
}
}Большое спасибо за уделенное время!
Это то, что я получаю, когда добавляю предупреждение в responseJson. Мне чего-то не хватает в php ??
Это тот же контент, который я помещаю в текстовые поля. Я имею в виду, что если я отправляю входные данные как «эй, пользователь» и «эй, пароль», они именно такие. Спасибо за ваше время!



![Безумие обратных вызовов в javascript [JS]](https://i.imgur.com/WsjO6zJb.png)


Каковы значения
UserEmailиUserPassword? Сделайтеconsole.info(UserEmail)после строкиconst { UserEmail } = this.state;