MySQL Database connection locally in flutter

1,479 views
Skip to first unread message

george ngugi

unread,
Apr 11, 2020, 3:47:38 AM4/11/20
to Flutter Development (flutter-dev)
Hey Team,

Am a flutter developer beginner, i want to connect the MySQL database locally. 

But its not connecting.

Thanks in advance for your assistance.


Here is my dart side

import 'dart:convert';
import 'package:http/http.dart' as http;
import 'Employee.dart';

class Registration {
static const ROOT = 'http://localhost/Agency/agency.php';

i have a folder in htdocs called Agency and i have save agency.php in it.







Here is my server code below :


<?php

$servename = "localhost";
$username ="root";
$password = "";
$dbname ="agency";
$table = "systemusers"; ///this is for create a table call

$action = $_POST["action"];

// create Connection
$conn = new mysqli($servename,$username,$password,$dbname);

// check th connection
if($conn->connect_error){
die("Connection Failed: ".$conn->connect_error);
return;
}

// if the connection is okay
if ("CREATE_TABLE"== $action){
$sql = "CREATE TABLE IF NOT EXISTS $table (
staff_id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
first_name VARCHAR(30) NOT NULL,
last_name VARCHAR(30) NOT NULL
)";

if ($conn->query($sql) === TRUE){
echo"save";
}
else{
echo"Error";
}
$conn->close();
return;

}

Suzuki Tomohiro

unread,
Apr 11, 2020, 8:03:53 AM4/11/20
to george ngugi, Flutter Development (flutter-dev)
What is error message?

--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/913056fd-c5fa-48a8-8446-855f4d263104%40googlegroups.com.

Mael Elvis FOSSO N.

unread,
Apr 11, 2020, 8:21:02 AM4/11/20
to Suzuki Tomohiro, george ngugi, Flutter Development (flutter-dev)
Does The problem come from Flutter or the server ?

Suzuki Tomohiro

unread,
Apr 11, 2020, 8:34:53 AM4/11/20
to Flutter Development (flutter-dev), george ngugi
Which part of your PHP shows that message?

On Sat, Apr 11, 2020 at 8:07 AM george ngugi <gngu...@gmail.com> wrote:
array(0) { }

Suzuki Tomohiro

unread,
Apr 11, 2020, 8:42:17 AM4/11/20
to Flutter Development (flutter-dev)
Your Flutter code is not sending correct data to your PHP.


If you need further assistance, would you share minimum reproducible PHP code and Flutter code? Both.

On Sat, Apr 11, 2020 at 8:38 AM george ngugi <gngu...@gmail.com> wrote:
$action = $_POST["action"];
Reply all
Reply to author
Forward
0 new messages