PHP parameter passing

3

I have a registration screen where the user can change their data and after clicking the 'Save changes' button changes are made to the database. Here is the button I created in the user edit window:

<input type="submit" name="atualizarusuario.php?id=<? echo $usuarios->fields['id_usuario']; ?>" value="Salvar alterações">

On the 'update user.php' screen I want to get this ID to update it and then display the message that the change was successful. I'm 'getting' the ID as follows:

 $id = $_GET['id'];

However, if I give a echo $id , it is not bringing the ID. What is wrong?

    
asked by anonymous 06.08.2015 / 20:58

2 answers

3

You can put the variable with the ID inside an input of type hidden and send it via post.

<input type="hidden" name="var" value="<?php echo $usuarios->fields['id_usuario']; ?>">

And then on another page:

$var = $_POST['var'];
    
06.08.2015 / 21:30
4

To send a parameter through the url (which uses the get method) this value must be placed in the action attribute of the form tag and not in the input submit. In the example the only field sent by get will be the id the others will be by post.

So:

<form method="post" action="gravar.php?id=<?php echo $usuarios->fields['id_usuario'];">

When submitting sensitive information, you should prefer to send by post, this is done with the creation of input hidden and the definition of post in the form tag method.

    
06.08.2015 / 21:15