I have a table in which columns 1 through 5 are fixed data that I feed into SQL and it appears the listing on the WEB page. In this WEB page I have a form in which the user should answer 3 questions, in inputs in columns 6 to 8.
It turns out that the worksheet is updating all the rows with the data answered in the last line. how do I fix it?
My update function:
function insereDado($conexao, $id, $campo6, $campo7, $campo8) {
$query = "update dbo.avalia_pf2 set campo6 = '{$campo6}', campo7 = '{$campo7}', campo8 = '{$campo8}' where id= {$id}";
$resultadoDaInsercao = mssql_query($query, $conexao);
return $resultadoDaInsercao;
My variables:
$id = 'id';
$campo6 = $_POST["campo6"];
$campo7 = $_POST["campo7"];
$campo8 = $_POST["campo8"];
My form:
<form action="adiciona-dado.php" method="post">
<table class="table table-striped">
<thead>
<tr>
<th class="titulo_cell">Título 1</th>
<th class="titulo_cell" >Título 2</th>
<th class="titulo_cell" >Título 3</th>
<th class="titulo_cell" >Título 4</th>
<th class="titulo_cell" >Título 5</th>
<th class="titulo_cell" >Pergunta 1</th>
<th class="titulo_cell" >Pergunta 2</th>
<th class="titulo_cell" >Pergunta 3</th>
</tr>
</thead>
<?php $dados = listaDados($conexao); foreach($dados as $dado) : ?>
<tbody>
<tr>
<td name="campo1"> <?php echo $dado['Campo1']; ?> </td>
<td name="campo2"> <?php echo $dado['Campo2']; ?> </td>
<td name="campo3"> <?php echo $dado['Campo3']; ?> </td>
<td name="campo4"> <?php echo $dado['Campo4']; ?></td>
<td name="campo5"> <?php echo $dado['Campo5']; ?> </td>
<td><input type="text" name="campo6" class="form-control"><? $dado['Campo6']?></input></td>
<td><input type="text" name="campo7" class="form-control"><? $dado['Campo7']?></input></td>
<td><input type="text" name="campo8" class="form-control"><? $dado['Campo8']?></input></td>
<td><button type="submit" class="btn">Incluir</button></td>
</tr>
</tbody>
<?php endforeach ?>
</table>
</form>
Important information: my ID is "NOT NULL" (not primary key with auto increment) How do I fix UPDATE? It is some information that I pass at the time of declaring the variable $ id but I am not able to reach the result.