Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $con=mysqli_connect("localhost","root","","flutterapp");
- $username=$_POST["username"];
- $password=$_POST["password"];
- $status=$_POST["status"];
- $qry=mysqli_query($con,"insert into user (username,password,status)
- values ('$username','$password','$status')");
- $response = array();
- echo json_encode($response); ?>
- import 'dart:convert';
- import 'package:flutter/material.dart';
- import 'package:http/http.dart' as http;
- class Register extends StatefulWidget {
- @override
- _RegisterForm createState() => _RegisterForm();
- }
- class _RegisterForm extends State<Register> {
- String _radioValue;
- TextEditingController user = new TextEditingController();
- TextEditingController pass = new TextEditingController();
- Future<List> register() async {
- final response =
- await http.post("http://myurl/flutterApp/register.php", body: {
- "username": user.text,
- "password": pass.text,
- });
- var datauser = json.decode(response.body);
- if (datauser.length == 0) {
- setState(() {
- msg = "Register Fail";
- });
- } else {
- Navigator.pushReplacementNamed(context, '/MyHomePage');
- }
- return datauser;
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- title: Text("Create New Account"),
- ),
- body: Container(
- margin: const EdgeInsets.only(left: 20.0,top:70.0, right: 20.0),
- child: Column(
- children: <Widget>[
- TextField(
- controller: user,
- decoration: InputDecoration(hintText: 'Username'),
- ),
- TextField(
- controller: pass,
- obscureText: true,
- decoration: InputDecoration(hintText: 'Password'),
- ),
- RaisedButton(
- child: Text("Sign Up"),
- onPressed: () {
- register();
- },
- ),
- ],),),);} }
Add Comment
Please, Sign In to add comment