I have a submit form function in flutter which will takes in three parameter and send them to the php backend to perform update operation on my sql database. The sql database is host and implemented using xampp.
static Future<bool> submitForm(
String userId, String userName, String userEmail) async {
final body = {
'id': userId,
'name': userName,
'email': userEmail,
'action': 'edit'
};
final headers = {'Content-Type': 'application/json'};
try {
var url = Uri.parse('${databaseUrl}/fetch_data.php');
var response = await http.post(
url,
headers: headers,
body: json.encode(body),
);
if (response.statusCode == 200) {
// Success!
bool result = response.body == 'true';
return result;
} else {
// Handle the error
throw Exception('Failed to edit user');
}
} catch (e) {
print('Error submitting form: $e');
rethrow;
}
}
And below is my php script $data = json_decode(file_get_contents('php://input'), true);
$id = $data['id'];
$name = $data['name'];
$email = $data['email'];
$sql = "UPDATE user SET name=?, email=? WHERE id=?";
$stmt = mysqli_prepare($conn, $sql);
mysqli_stmt_bind_param($stmt, "sss", $name, $email, $id);
if (mysqli_stmt_execute($stmt)) {
http_response_code(200);
return 'true';
} else {
http_response_code(500);
return 'Internal Server Error';
error_log("SQL error: " . mysqli_error($conn));
}
mysqli_stmt_close($stmt);
mysqli_close($conn);
For some reason, I am not able to update the data in the table after firing the request. The response I received in flutter app is with statuscode 200 and the body is empty. I am hosting the php file with localtunnel so I not quite sure how can I view the log in php to debug.
Appreciate for any helps in advance.