0
I have a course management system where the user has access to a table with all classes of all courses and chooses to enroll in a.
When the user is going to register, will open a form with the fields that he must fill and the field with the name of the formation and class, however, these fields I want to be already filled according to the formation and class of the row of the table that he clicked.
The query table:
<h1 style="
text-align: center;
height: 7;
margin-top: 150;
margin-bottom: 70
margin-top:130;
"> Consulta de turmas </h1>
<form method="post" action="selectT.php">
<div class="col-lg-3">
<div class="form-group">
<label for="NOME">Nome: </label>
<input class="form-control" id="NOME" placeholder="Nome da turma" name="NOME">
</div>
</div>
<div class="col-lg-3">
<div class="form-group">
<label for="DATA">Data</label>
<input class="form-control" id="DATA" placeholder="Data da formação" name="DATA">
</div>
</div>
<div class="col-lg-3">
<div class="form-group">
<label for="LOCAL">Local: </label>
<select class="form-control" id="LOCAL" name="LOCAL">
<option>PR</option>
<option>PL</option>
<option>SP</option>
<option>RJ</option>
<option>FR</option>
</select>
</div>
</div>
<button type="submit" class="btn btn-primary" style="margin-top: 22;">Buscar</button>
</form>
<?php
//Conexão e consulta ao Mysql
mysql_connect('localhost','root','') or die(mysql_error());
mysql_select_db('db_formacao') or die(mysql_error());
$qry = mysql_query("select * from turmas");
//Pegando os nomes dos campos
$num_fields = mysql_num_fields($qry);//Obtém o número de campos do resultado
for($i = 0;$i<$num_fields; $i++){//Pega o nome dos campos
$fields[] = mysql_field_name($qry,$i);
}
//Montando o cabeçalho da tabela
$table = '<table class="table table-hover table-inverse" style="margin-top:50;background-color: #37444a; color:lightgrey;"> <tr>';
for($i = 0;$i < $num_fields; $i++){
$table .= '<th>'.$fields[$i].'</th>';
}
//Montando o corpo da tabela
$table .= '<tbody style="
background-color: #86979e;
color: #37444a;
">';
while($r = mysql_fetch_array($qry)){
$table .= '<tr>';
for($i = 0;$i < $num_fields; $i++){
$table .= '<td>'.$r[$fields[$i]].'</td>';
}
// Adicionando botão de exclusão
$table .= '<td><form action="inscricao.php" method="post">'; //formulário com método post que vai para deleteF.php
$table .= '<input type="hidden" name="ID" value="'.$r['ID'].'">';
$table .= '<button class="btn btn-primary">Inscreva-se</button>'; //aqui está o seu botão
$table .= '</form></td>';
}
//Finalizando a tabela
$table .= '</tbody></table>';
//Imprimindo a tabela
echo $table;
?>
The application form:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "db_formacao";
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT NOME FROM turmas";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
$row = $result->fetch_assoc();
}
?>
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<h1 style="
margin-top:100px;">Inscrição</h1>
<p> </p>
<p class="lead"></p>
<ul class="list-unstyled">
<form id="cadastro" method="post" action="banco/updateP.php" style="
text-align: left;
margin-top:50px;">
<div class="col-lg-12">
<div class="form-group" style="
text-align: left;">
<label for="FORMACAO">Formação: </label>
<input type="text" required class="form-control" id="FORMACAO" name="FORMACAO" value="<?=$row['nome']?>">
</div>
</div>
<div class="col-lg-12">
<div class="form-group" method="post" style="
text-align: left;">
<label for="TURMA">Turma: </label>
<input type="text" required class="form-control" id="TURMA" name="TURMA">
</div>
</div>
<div class="col-lg-12">
<div class="form-group" method="post" style="
text-align: left;">
<label for="COLABORADOR">Colaborador: </label>
<select class="form-control" id="COLABORADOR" name="COLABORADOR">
<?php
?>
</select>
</div>
</div>
<div class="col-lg-12">
<div class="form-group" method="post" style="
text-align: left;">
<label for="PREVISTO">Status: </label>
<input type="text" required class="form-control" id="PREVISTO" name="PREVISTO" value="Previsto">
</div>
<div class="form-check form-check-inline disabled">
<label class="form-check-label">
<input class="form-check-input" type="radio" name="STATUS" id="STATUS" value="Realizado" disabled> Realizado
</label>
</div>
<div class="">
<button type="submit" class="btn btn-primary btn-lg btn-block">Salvar</button>
</div>
</div>
</form>
</ul>
</div>
</div>
</div>
The consultation:
The form:
because almost all people still use
mysql_*
? should redo for PDO or Mysqli or if not your site is exposed to various types of attacks...– 13dev
I use an old version of php and can not change because there are many systems running in this version.
– Mariana Bayonetta
what is the php version ?
– 13dev
The version is php 5.2.10
– Mariana Bayonetta