簡體   English   中英

從表單傳遞值以改變文件PHP而不使用POST

[英]Pass value from form to alter file PHP without POST

我試圖通過表單傳遞來自數據庫的值。 由於POST操作,我在表單上放了n_processo(primarykey),因此POST可以將它傳遞給文件並編輯表。 我不希望這個值出現在表(Form)上,因為它只是readonly,所以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");
?>

嘗試這個:

<?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;?>"/>

隱藏字段與文本字段的工作方式相同。

它們的值只能在頁面加載時通過PHP設置或通過JavaScript事件設置。

唯一的區別是它們在瀏覽器上不可見。

但是,它們可以在頁面的View Source中看到。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM