How to make a simple shopping system?

Asked

Viewed 1,182 times

-4

Example: I have a product with 10 units registered in a database, a customer buys 1 unit, this unit gives low and product quantity goes to 9 units.

How to express this in PHP?

  • Hello Marcelo Gomes, welcome to [pt.so]. I noticed that I had several questions closed recently. I suggest you read the guide [Ask] and make a [tour] to increase your chances of getting a good answer.

1 answer

5

Any system has as a basis for managing information several databases such as Mysql, Postgresql, MARIADB ... CRUD is independent of the programming language used.

CRUD are four basic operations used in relational databases to manage all information to be stored, searched and deleted.

  • C - Create - Create the information ...
  • R - Read - Read the information ...
  • U - Update - Update information ...
  • D - Delete - Delete information ...

From the moment you understand and understand the CRUD process you will be able to interact with the SGDB of your choice. One of the most widely used on the market is Mysql, mainly when it comes to PHP programming language.

Once you store all your information within variables and send and receive the necessary information via commands $_GET[], $_POST[] and $_REQUEST[], you can send and receive them from your Mysql. In most cases, this information travels via the above mentioned forms or commands.

Example of sending and receiving information:

  • $produto = $_POST['nome_produto'];
  • $preco = $_POST['preco'];
  • $quantidade = $_POST['quantidade'];

Example of connection to the database

  • mysql_connect('host', 'user', 'pass');
  • mysql_select_db('db');

Use Mysqli or PDO, Mysql is being discontinued.

Once you are connected to the database, use Xampp or Wampserver to work on a local machine (localhost, on your pc), you can start using CRUD ...

CRUD

  • C - mysql_query("INSERT INTO (colunas) VALUES (valores) ...);
  • R - mysql_query("SELECT * FROM vendas WHERE id_compra = '10');
  • U - mysql_query("UPDATE vendas SET pago = 'pago' WHERE id_compra = '10';
  • D - mysql_query("DELETE FROM vendas WHERE id_compra = '10'");

There is vital information for all people who need to start treading the path of stones in the programming area.

Browser other questions tagged

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