我正在使用 React Native 开发移动应用程序。问题是我似乎无法将任何内容插入数据库。我有一个注册页面,用户需要在其中编写用户名和密码(并重复该密码),几个月前该页面运行良好。我没有更改该特定页面上的任何内容,但是当我开始添加新页面时,例如另一个不起作用的页面,它停止工作并给了我可以在此处看到的警告:
另一个不起作用的页面是用户可以在其中发布带有标题日期等的工作。此页面尚未完成,但应该已完成,以便用户可以将某些内容发布到数据库,但它给了我可以在此处看到的错误:
注册页面的代码如下(不包括样式表):
import React, { Component } from "react";
import { View, Text, StyleSheet, Alert, TextInput, ImageBackground, Image, AsyncStorage, TouchableOpacity } from "react-native";
import { Button, Icon, withTheme } from 'react-native-elements';
const SIGNUP_URL = 'http://kamilla-server.000webhostapp.com/app/signUp.php';
class SignUp extends Component {
constructor(props) {
super(props);
this.state= {
email: '',
password: '',
password2: '',
};
}
async onSignUp() {
const { email, password, password2 } = this.state;
if(this.state.email != '' && this.state.password != '' && this.state.password2 != '') {
if(password != password2) {
Alert.alert('Password matcher ikke', 'De to indtastede passwords skal være det samme password')
} else {
const response = await fetch(SIGNUP_URL, {
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
method: 'POST',
body: JSON.stringify({ email, password }),
})
const data = await response.json()
if (data.error) {
alert(data.error)
} else {
AsyncStorage.setItem('UserID', data.user.UserID)
this.props.navigation.navigate('SignUpMessage')
}
}
} else {
Alert.alert('Tomme felter', 'Venligt indtast email og password for at kunne oprette en bruger')
}
}
杨魅力
回首忆惘然