How insert data in MariaDB using docker and save changes of Database?

I am writing here because I am new in Docker world. In the past, I was using Vagrant in developing stuff. Installing OS + packages that I need was very easy. Now, Vagrant is load more resources than I expected. I am changing to Docker and I made PHP environment. In docker-compose.yml load LAMP: Linux, Apache, MariaDB, and PHP as below.

services:
foo_php:
    build: .
    volumes:
        - ./src:/var/www/html
    ports:
        - 9002:80
foo_db:
    image: mariadb:latest
    restart: always
    environment:
        MARIADB_ROOT_PASSWORD: Password1234
        MYSQL_ROOT_HOST: '%'
    volumes:
        - ./mariadb:/var/lib/mysql
phpmyadmin:
  image: phpmyadmin:latest
  restart: always
  ports:
    - 9003:80
  environment:
    - PMA_ARBITRARY=1enter code here

and in Dockerfile, I made this:

FROM php:8.3-apache

MAINTAINER Senior Moe <[email protected]>

WORKDIR /var/www/html

RUN apt update -y && apt upgrade -y && apt install libmariadb-dev -y

USER root

RUN sed -i -e "/^bind-address/d" /etc/mysql/my.cnf

RUN docker-php-ext-install mysqli

Now in my sign up page, I made this:

    <?php
include_once "connection_db.php";

if(isset($_POST['your_name']) && isset($_POST['your_email']) && isset($_POST['your_passwrd']) && isset($_POST['repeat_passwrd']) ){
   function validation($input){
       $input = trim($input);
       $input = stripslashes($input);
       $input = htmlspecialchars($input);

       return $input;
   }

   $username = validation($_POST['your_name']);
   $user_email = validation($_POST['your_email']);
   $user_password = validation($_POST['your_passwrd']);
   $repeat = validation($_POST['repeat_passwrd']);

  
       $check_query = "SELECT * FROM users WHERE user_email='$user_email'";
       $result_check = mysqli_query($connection, $check_query);
       if(mysqli_num_rows($result_check) === 1 ){
           header("Location: ../index.php?registererror=The Email already exist");
           exit();
       }else{
           $hashed_password = password_hash($user_password, PASSWORD_DEFAULT);
           $record_db = $connection->prepare("INSERT INTO users (username, user_email, user_password) VALUES (?,?,?)");
           $record_db->bind_param("sss",$username, $user_email, $user_password);
           header("Location: ../index.php?status=User Registe Seccessfully!");
           exit();
       }
   
}else{
    header("Location: ../index.php");
    exit();
}

In this post, I delete lines for validation to shortcut the question. In example above, if I test the sign up, the inserting not make insert in database.

Q1. How insert into database?
Q2. How save changes in database’s structures after finish or for completing development in the future?

Updating:
Here, how I am connecting to database:

<?php

$server_db = [
    "server_name" => "foo_db",
    "server_user" => "root" ,
    "server_passwd" => "Password1234",
    "database_name" => "FOO_DB"
];

$connection = mysqli_connect($server_db['server_name'],$server_db['server_user'],$server_db['server_passwd'],$server_db['database_name']);

if(!$connection){
    echo "connection faild!";
}

8

To save Database make volume for database files by docker-compose.yml file:

services:
foo_php:
    build: .
    volumes:
        - ./src:/var/www/html
    ports:
        - 9002:80
foo_db:
    image: mariadb:latest
    restart: always
    environment:
        MARIADB_ROOT_PASSWORD: Password1234
        MYSQL_ROOT_HOST: '%'
    volumes:
        - ./mariadb:/var/lib/mysql #here
phpmyadmin:
  image: phpmyadmin:latest
  restart: always
  ports:
    - 9003:80
  environment:
    - PMA_ARBITRARY=1
volumes:
  mariadb: #here

to write in database, the php was missing records:

<?php
include_once "connection_db.php";

if(isset($_POST['your_name']) && isset($_POST['your_email']) && isset($_POST['your_passwrd']) && isset($_POST['repeat_passwrd']) ){
   function validation($input){
       $input = trim($input);
       $input = stripslashes($input);
       $input = htmlspecialchars($input);

       return $input;
   }

   $username = validation($_POST['your_name']);
   $user_email = validation($_POST['your_email']);
   $user_password = validation($_POST['your_passwrd']);
   $repeat = validation($_POST['repeat_passwrd']);

  
       $check_query = "SELECT * FROM users WHERE user_email='$user_email'";
       $result_check = mysqli_query($connection, $check_query);
       if(mysqli_num_rows($result_check) === 1 ){
           header("Location: ../index.php?registererror=The Email already exist");
           exit();
       }else{
            $hashed_password = password_hash($user_password, PASSWORD_DEFAULT);
           $record_db = $connection->prepare("INSERT INTO users (username, user_email, user_password) VALUES (?,?,?)");
           $record_db->bind_param("sss",$username, $user_email, $hashed_password);
       $record_db->execute(); //this was missing.
       $record_db->close(); //this for closing. 
           header("Location: ../index.php?status=User Registe Seccessfully!");
           exit();
       }
   
}else{
    header("Location: ../index.php");
    exit();
}

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật