PHP passing parameters

Asked

Viewed 854 times

3

I have a registration screen where the user can change his data and after clicking the 'Save changes' button the changes are made in the database. Follow the button I created in the user editing window:

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

On the 'actualizrusuario.php' screen I want to take this ID to the top of it to update and then display on this screen the message that the change was successfully made. I’m getting the ID like this:

 $id = $_GET['id'];

however, if I give a echo $id, is not bringing the ID. What the error?

2 answers

4

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

Thus:

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

When sending confidential information prefer sending by post, this is done with the creation of Hidden input and the definition of post in the form tag method.

3


You can place 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 the other page:

$var = $_POST['var'];

Browser other questions tagged

You are not signed in. Login or sign up in order to post.