php I/扑动(27225):格式异常:意外字符(在字符1处)I/flutter(27225):< br />I/扑动(27225):^

wvt8vs2t  于 2023-01-24  发布在  PHP
关注(0)|答案(1)|浏览(97)

我想插入注册数据从用户到我的数据库。我用这段代码这样做。但是,我得到了这个问题,我不知道是什么问题以及解决方案。有人能帮助我吗?
这是我在register类中的函数

TextEditingController email = TextEditingController();
  TextEditingController password = TextEditingController();
  TextEditingController name = TextEditingController();
  TextEditingController username = TextEditingController();
  TextEditingController cPassword = TextEditingController();

  
  final _formKey = GlobalKey<FormState>();
  bool isRememberMe = false;

  validateUserEmail() async {
    try {
      var res = await http.post(Uri.parse(API.validateEmail), body: {
        'e-mail': email.text.trim(),
      });
      if (res.statusCode == 200) {
        //connection successful
        var resBody = await jsonDecode(res.body);

        if (resBody['emailFound'] == true) {
          Fluttertoast.showToast(
              msg: "Email already been used. Please try another email");
        } else {
          //register & save
          registerAndSaveUserrecord();
        }
      }
    } catch (e) {
      print(e.toString());
    }
  }

  registerAndSaveUserrecord() async {
   
    try {
     
      var headers = {'Content-Type': 'application/json'};
      var url = Uri.parse(API.register);
      Map body = {
        'username': username.text,
        'email': email.text.trim(),
        'name': name.text,
        'password': password.text,
        'cPassword': cPassword.text,
      };
      http.Response response =
          await http.post(url, body: jsonEncode(body), headers: headers);

      if (response.statusCode == 200) {
        //connection successful
        final json = jsonDecode(response.body);
        if (json['success'] == true) {
          Fluttertoast.showToast(msg: "Register Successful!");
        } else {
          Fluttertoast.showToast(msg: "Error Occurred. Try Again!");
        }
      }
    } catch (e) {
      print(e.toString());
    }
  }

我使用这个函数时,用户点击注册按钮。这里是我的php文件注册。

<?php

 include '../connection.php';

 //POST (send/save data to mysql)
 //GET (retrieve/read from mysql)

 $username = $_POST['username'];
 $email = $_POST['email'];
 $name = $_POST['name'];
 $password = md5($_POST['password']); //pass to binary for secure purpose
 $cPassword = md5($_POST['cPassword']);

 $sql = "INSERT * INTO user WHERE email = '$email' , name = '$name' , username = '$username' ,  password = '$password' , cPassword = '$cPassword'";

 $result = $connect => query($sql);

 if($result){

    echo json_encode(array("success" => true ));
 }

 else {
    echo json_encode(array("success" => false ));
 }

我是新来的所以有点困惑。
这是在我做print(res.body)的时候出现的,这是什么意思?

zsbz8rwp

zsbz8rwp1#

同样的问题发生在我身上,我为我的数据库创建了新用户,并在php文件中用我新创建的用户名和密码替换用户名和密码,它对我来说工作得很好。

相关问题