Add PHP log to Mysql database

Asked

Viewed 145 times

0

I wanted to create in PHP something similar to what I show in the image to add records in the database:

inserir a descrição da imagem aqui

Someone can help me, since I’m new in PHP?

  • I assume you are aware of database so try to start designing the database and the table adds the fields with corresponding type, it will be easier to start in php, when you can try to search for conectar a base de dados PHP

  • I already have it ready, both the database and the part of the connection, as well as I already have a page ready in php database query, now I have to do this to insert the records

1 answer

3


I’ll try to give you a little help

First

First of all design your database so that in php it is easier.

2nd Second

Already with the database thought create your connection file (Connect.php) I leave here a small example:

<?php
// qual é o servidor que estas a te conectar
$servidor = "localhost";

// nome de utilizador para acessar a base de dados
$user = "root";

// password do utilizador
$password = "password15634";

// qual é a base de dados a se conectar
$db = "base_de_dados";

// Cria a conexão e guarda-a numa variável para ser acessível mais tarde
$conn = new mysqli($servidor, $user, $password, $db);

// Verificar se a conexao foi bem sucedida!
if ($conn->connect_error) {
    die("A conexao com a base de dados falhou, mais detalhes: " . $conn->connect_error);
}

Third

With your connection file created, attach it to another php script(page) (index php.) let’s try to insert in the database here the example of index php.

//Incluimos o nosso arquivo de conexão para que possamos usar a variavel $conn
include('Connection.php');

// Vamos fazer a primeira requisição a base de dados
$stmt = $conn->prepare("INSERT INTO minha_tabela (produto, unid, qtd) VALUES (?, ?, ?)");

// ler mais aqui: http://php.net/manual/en/pdo.prepared-statements.php
// vamos associar os ? com os valores pretendidos
$stmt->bind_param("ssi", $produto, $unid, $qtd);

// Vamos Atribuir valores para que possa ser introduzido na tabela exemplo
$produto = "Pneu de carro";
$unid = "09887234234";
$qtd = 4;

// finalmente executamos a nossa requisição a base de dados
$stmt->execute();

If all goes well a record will be entered in the table minha_tabela these values:

$produto = "Pneu de carro";
$unid = "09887234234";
$qtd = 4;

I hope I’ve helped,

To better understand your knowledge in php in the connection part of the database I suggest you enter these Links: (example links should have ai better sites)

  • In the product part and in the room I wanted to use a combobox already with the products and rooms that exist in the database appear and when I choose the product automatically assign the unit, can you help me to create this form?

  • 13dev, thanks for your help, I already have the form almost ready, I only have a problem, which is to select the product I want to fill me automatically the unit associated.

Browser other questions tagged

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