将值从表单传递到无需开机自检即可更改文件 PHP



我正在尝试使用表单从我的数据库中传递一个值。由于 POST 操作,我将n_processo(主键(放在表单上,以便 POST 可以将其传递给文件并编辑表。我不希望此值出现在表(窗体(上,因为它是只读的,以便 POST 可以看到它并编辑值。有谁知道如何改变这一点?

表单文件:

<form action="alterar_aluno3.php" method="POST">
<table>
<tr>
    <th width="15%">Nº de Aluno</th>
    <td><input type="text" maxlength="5" class="input-field4" name="teste" readonly value="<?php echo $idaluno;?>"/></td>
  </tr>
<tr>
    <th width="20%">Pessoas com quem vive:</td>
    <td><input type="text" class="input-field4" name="agregado_existente" value="<?php echo $agregado_existente;?>"/></td>
  </tr>
</table>
<p align=right>
<!--alterar este botao -->
<button type="submit" value="Alterar">Alterar</button>
<button type="cancel" onclick="window.location='http://donutsrool.pt/ficha_aluno.php';return false;">Cancelar</button>
</p>
</form>

插入文件:

<?php
    include "functions.php";
    session_start();
    //captar os dados recebidos do formulário com o método POST
    $idaluno1=$_POST['teste'];
    $agregado_existente = $_POST['agregado_existente'];
    $altera="UPDATE aluno SET `agregado_existente`='$agregado_existente' WHERE `n_processo`=$idaluno1;";
    $resultado =DBExecute($altera);
    header("Location: ficha_aluno.php");
?>
您可以将

id 放在hidden字段中,而不是文本字段中。

<input type="hidden" maxlength="5" class="input-field4" name="teste" value="<?php echo $idaluno;?>"/>

隐藏字段的工作方式与文本字段相同。

它们的值只能在页面加载时或通过 JavaScript 事件使用 PHP 设置。

唯一的区别是它们在浏览器上不可见。

不过,可以在页面的"查看源代码"中看到它们。

试试这个:

<?php
    include "functions.php";
    session_start();
    //captar os dados recebidos do formulário com o método POST
    $idaluno1=$_POST['teste'];
    $agregado_existente = $_POST['agregado_existente'];
    $altera="UPDATE aluno SET `agregado_existente`='$agregado_existente' WHERE `n_processo`='$idaluno1'";
    $resultado =DBExecute($altera);
    header("Location: ficha_aluno.php");
?>

最新更新