0
I have a table where columns 1 to 5 are fixed data that I feed SQL and it appears the listing on the WEB page. On this WEB page I have a form in which the user must answer 3 questions, in inputs in columns 6 to 8.
It turns out that the spreadsheet is updating all the lines with the dice answered in the last line. how do I fix?
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’s some information I pass when declaring the $id variable but I’m not getting the result.
I could not understand, where I insert the var_dumb($id)
– user78432
function insereDado($conexao, $id, $campo6, $campo7, $campo8) {
var_dump($id);
$query = "update dbo.avalia_pf2 set campo6 = '{$campo6}', campo7 = '{$campo7}', campo8 = '{$campo8}' where id= {$id}";
$resultadoDaInsercao = mssql_query($query, $conexao);
return $resultadoDaInsercao;
– Cesar Vinicius
Hasn’t worked yet.
– user78432
How do you assign the value of the $id variable and then send it to the function?
– Cesar Vinicius
$id = 'id'; I also tried $id = $_POST["id"]; and $id = $_GET["id"];
– user78432
When you give a submit in your form, it will take all that information and send it to the add-data.php page, right? well, on this page I imagine you have: `
– Cesar Vinicius
When you give a submit in your form, it will take all that information and send it to the add-data.php page, right? well, on this page I imagine you have: ` $campo6 = $_POST["campo6"]; .. You need to have something referencing the ID can be $id = 4 if you want to manually pass the id value to the variable, or $id = $_POST['id'] if it’s coming from there your form. From what I saw in your code you didn’t.
– Cesar Vinicius
Hi... so the ID does not come from the form, I import a spreadsheet to SQL, columns 6, 7 and 8 have inputs to answer by form..
– user78432