Passing data from a form on a page to another page for textbox

Asked

Viewed 144 times

1

How do I pass the data of a form (query.php) of a page to the textbox and a radiobutton of the form (register.php) of another page without the action ? Because I have two Ubmit buttons for that same form (query.php) and I would not like to use the action for the 2, I would just like to open the other page (register.php) with the textbox and radiobutton filled in by the form of the other page (query.php) with a Ubmit button, the other button of the.php query page I would like when triggered to remain on the same page (query.php).

The code of the.php query:

if(isset($_POST['excluir'])){
            foreach($_POST['selecionado'] as $cpf){
               $sql = "DELETE FROM tbl_usuario WHERE cpf = '$cpf'";
                $result = mysqli_query($strcon,$sql) or die("<script type='text/javascript'>alert('Erro ao tentar deletar usuário');</script>");
            }
        }
        else if(isset($_POST['alterarConsulta'])){
            foreach ($_POST['selecionado'] as $cpf){
                $linhas[] = 1;
            }
            if(count($linhas) == 1){
                $sql = "SELECT * FROM tbl_usuario WHERE cpf = '$cpf'";
                $result = mysqli_query($strcon,$sql) or die("<script type='text/javascript'>alert('Erro no acesso aos dados');</script>");
                $dados = mysqli_fetch_array($result);
                $altcpf = $dados['cpf'];
                $altnome = $dados['nome'];
                $altsexo = $dados['sexo'];
                $altidade = $dados['idade'];
                $altcidade = $dados['cidade'];
                $alttelefone = $dados['telefone'];
                $altemail = $dados['email'];

                header("Location: cadastro.php");
            }
            else{
                echo "<script type='text/javascript'>alert('Selecione uma linha');</script>";
            }
        }

1 answer

3


Assuming the button is linked to the line that will be edited and with an ID related to it can be used

jQuery('.meuBotao').click(function(){
    var id = $(this).attr("id");
    location.href = "meudominio.com?id="+id+"";
});

This way will redirect the user to another page with a GET taking the ID of the button that was clicked, this ID must be the same as the user you want to edit, and then on your other page you recover this ID with the $_GET["id" method] and do a database search by the same with the ID, the returned data you add to the form within each input value

Browser other questions tagged

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