Passing values through variable does not work

Asked

Viewed 72 times

0

I’m using the MDL(google) framework to make a registration system, and in the part of changing the information in the database, in passing the values through the url, only some are passed and others are not. In addition, the name and surname of do not appear in the form, although the url received both. Here is the code: page showing the data(clients.php):

    $seleciona="select * from cadastro_clientes";
    $sql=mysqli_query($con,$seleciona);
        while ($reg=mysqli_fetch_assoc($sql)) {
        echo "
         <tr>
        <td class=mdl-data-table__cell--non-numeric>$reg[nome]</td>
        <td class=mdl-data-table__cell--non-numeric>$reg[endereco]</td>
        <td class=mdl-data-table__cell--non-numeric>$reg[numero]</td>
        <td class=mdl-data-table__cell--non-numeric>$reg[dada_comemorada]
        </td>
        <td class=mdl-data-table__cell--non-numeric>
        <a href=form_edit.php?ru="
        .urlencode($reg['nome']).
        "&en=".urldecode($reg['endereco']).
        "&nu=".urldecode($reg['numero']).
        "&da=".urldecode($reg['dada_comemorada']).
        ">Editar</a></td>
        </tr>";
                }

                ?>  

page that should show the data to change(form_edit.php):

       <?php
       include"conecta.inc";
       $recebenome=$_GET['ru'];
       $recebeendereco=$_GET['en'];
       $numero=$_GET['nu'];
       $data=$_GET['da'];
       ?>


     <div class="page-content">
            <form action="cadastrar.php" method="post" name="cadastro">
              <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
                <input class="mdl-textfield__input" type="text" id="sample3" name="nome" value=<?php echo $recebenome;?>>
                <label class="mdl-textfield__label" for="sample3">NOME</label>
              </div><br>
              <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
                <input class="mdl-textfield__input" type="text" id="sample3" name="endereco" value=<?php echo $recebeendereco;?>>
                <label class="mdl-textfield__label" for="sample3">ENDEREÇO</label>
              </div><br>
              <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
                <input class="mdl-textfield__input" type="text" id="sample3" name="numero" value=<?php echo $numero;?>>
                <label class="mdl-textfield__label" for="sample3">NUMERO</label>
              </div><br>
              <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
                <input class="mdl-textfield__input" type="text" id="sample3" name="data" value=<?php echo $data;?>>
                <label class="mdl-textfield__label" for="sample3">DATA COMEMORADA</label>
              </div><br>

                <input type="submit" value="SALVAR" class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent">

            </form>

          </div>

in the url the name and surname passes, but does not appear in the form, and the number and date give the error "Notice: Undefined index: nu in C: xampp htdocs Bjorn form_edit.php on line 5", but if I register a client without space, all appear normally. I don’t know why this, since I used urlencode :/

note, when I click on the client that is unwritten without separating the words by space: inserir a descrição da imagem aqui

now when I click the registered client with spaces separating the name and surname, and the address (note that the url takes the name and surname, but not the full address: inserir a descrição da imagem aqui

  • Undefined index: nu means that $_GET['nu']; this does not exist, which means that there is no parameter in the url (query string) for nu

  • but why when I register a client without using the spaces the parameter is normally found?

  • Give an example of the two url’s, when it is caught and when it is not

  • for example, if I register the name as "Jondoe", it takes all the data and normally shows, however, if register as "Jon Doe", with the use of spaces, the form only shows "Jon", although the url shows that the page received "Jon Doe"but in the number and date of birth do not appear, appears the error quoted above

  • In Edit is <a href=form_edit.phpru=. Shouldn’t be <a href=form_edit.php?ru=. So I really suggest copying and pasting the url when it works and when it doesn’t work for the question so that the problem is clear and the same can be replicated.

  • Thanks for the suggestions updated the post by placing the images. I checked the code in the part you spoke, and it’s correct in my document, I don’t know why it’s wrong here, I must have accidentally deleted it

  • From what I see the URL of Edit is not being built with all values, but only the first 2. I started by confirming that the variable $reg has the values that is intended with print_r($reg) exactly before the Edit link

  • First: is the list displayed with all the right links? If any link is not right, are the ones with spaces? Second: details only work when the link is right or there are records that the link is right but details are not displayed?

Show 3 more comments

1 answer

0


The first provision is to put URLENCODE for all parameters.

<a href=form_edit.php?ru="
.urlencode($reg['nome']).
"&en=".urlencode($reg['endereco']).
"&nu=".urlencode($reg['numero']).
"&da=".urlencode($reg['dada_comemorada']).
">Editar</a>

And the second provision is on the page (form_edit.php):

The space will become an attribute separator and everything after the space will be seen as input element attribute.

The solution is to quote all values of inputs:

example value="<?php echo $recebenome;?>"

<input class="mdl-textfield__input" type="text" id="sample3" name="nome" value="<?php echo $recebenome;?>">

If you check the source code - without quotes in values - you will see that the inputs are with the data entered correctly, but in the page view only the first part appears and it is only this part that will be submitted to the page cadastrar.php.

<input type=text id=sample3 name=endereco value=Fulano de Tal>

<input type=text id=sample3 name=endereco value="Fulano de Tal">

Another example: imagine my name is Fulano style=color:red to correctly pass my name have to hug with quotes otherwise style=color:red will be interpreted as input element attribute.

<input type=text id=sample3 name=endereco value="Fulano style=color:red">

<input type=text id=sample3 name=endereco value=Fulano style=color:red>

  • Thank you very much! The problems were exactly these!

Browser other questions tagged

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