How to insert data from a form made in Angular2 in a database?

Asked

Viewed 93 times

-1

I’m starting to learn Angular 2, and I have to do a CRUD of a system over series, and I need to store data in a database, currently I know how to use Mysql using Xampp.

I need to make the request using Ajax. Below, follows the function that you want to call the PHP file: inserir a descrição da imagem aqui

Below, the file 'register.php':

inserir a descrição da imagem aqui

I’m testing the function of the first image using ng serveto enable the HTTP server for Angular, but the PHP file does not work, I believe it is due to the lack of a Mysql server similar to the one that Xampp activates, because I know that Angular is Client-side, and PHP server-side.

1- How can I connect to the bank?

2- How can I "call" the server-side?

Thank you in advance.

  • Usually the server side is called via http requests.

  • Yes, but I was not able to do that, I figured out how to make it work, compiling angular code 2 and running inside the xampp, soon I will post as answer.

1 answer

0


The solution to this problem using xampp is:

  1. Place all PHP files in the htdocs folder of xampp.
  2. Develop the web application and use the command ng build to compile the system.
  3. Take the 'dist' folder that was created inside the project and copy it to the htdocs folder.
  4. Open xampp, connect Apache server and if necessary Mysql.
  5. Access the application.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.