Variable value without space in PHP/ HTML input

Asked

Viewed 44 times

-1

I’m having a problem printing a value of a php variable into an html form.

I printed without spaces, but in the table the data comes normal from the database.

Example: Testing test b

he prints Testeb in the input.

I just want it to print out the way it’s in the bank.

<html>
    <head>
    
        <link href="./estilo/estilo.css" rel="stylesheet">
        <script lang="javascript" src="./javascript/jquery.min.js" ></script>
        <script lang="javascript" src="./javascript/validacao.js" ></script>
        <script lang="javascript" src="./javascript/busca.js" ></script>

        <meta charset="UTF-8">
    </head>    
    
    <body>
        

        
        <header class="menu">
           
            <div class="menu-container">
        
                <h1> Search</h1>
                <p id="texto"></p>
     
        
            </div>
        </header>

        <? 
        $editar = $_GET['id'];
  
        $sql = "select * from cliente   where i_cliente =  $editar  ";

        require_once  "conexao.php";

        $c = new conexao();

        $edicao_dados = mysqli_query($c -> conexao(),$sql);
        
        ?>
            <?php while($alterar = mysqli_fetch_array($edicao_dados)){?>
       

            <form  class="formulario" id="pesquisa" method="POST"   action="incluir.php" name="formulario" enctype="multipart/form-data">
                <p>
                

                
               <?php $nome = $alterar[1];
               
               ?>

                <label>Nome</label><br><input type="text" name="nome"  class="entrada-dados"   value="<?php echo $nome.'\t'?>">
                <span  class="hint">Digite por exemplo:Jonatas de Sá silva</span>
                </p>
               
                <p>
                    <label>CPF</label><br><input  value="<?php echo $alterar[3]?>" class="entrada-dados"type="text" name="cpf" >
                    <span class="hint">Digite por exemplo:161.306.887-50</span>
                </p>

                <label>CNPJ</label><br><input type="text" name="cnpj"  class="entrada-dados"   value="<?php echo "{$alterar[2]}"; ?>"><br>
                <button   type="button" onclick="validar()"class="cadastrar1-btn" name="enviar3">Cadastrar33</button>
                <!-- <input type="submit" onclick="validar()"  class="cadastrar-btn" name="enviar" value="Cadastrar" >-->
                <input type="submit" onclick="validar()"  class="alterar-btn" name="alterar" value="Alterar" ><br>
                <input type="file" onclick="validar()"  class="importar-btn" name="alterar" value="Importar dados..." >
                

                <hr>
                <input name="id_cliente" type="hidden " value="<?php echo $alterar[0]?>"></input><br>
               <input type="search" class="pesquisa" class="buscar-dados"   placeholder="O que deseja buscar??" >
               
               <select class="opcao" >
                   
                   <option   name="nome">nome</option>
                   <option   name="CPF">CPF</option>
                   <option   name="CNPJ">CNPJ</option>
               
                </select>
                
               <a class="btn-aparecer">Buscar</a>
           
            <table  border="1px solid" class="tabela clear" width="600px" height="300px">
                <tr>
                    
                    <th>Nome</th>
                    <th>CNPJ</th>
                    <th>CPF</th>
                    <th>Ação</th>
           
                    <tr>
                    

                    <?php
                    
                    
                    
                  /*
                    function excluirCadastro(){
                        $excluir = "delete cliente where i_cliente = $id";

                        $excluido = mysqli_query($excluir);

                        if($excluido != 0){
                            echo "Erro ao Excluir";

                        }else{
                            echo "Excluido com Sucesso!"; 
                        }
                    }
                    */

           //busca todos dados para fazer regaginacao
                    require_once "conexao.php";
                    $c = new conexao();

                    $busca = "select * from cliente";


                    $total_registros_pagina = 20;
            
            
                    $pagina = $_GET['pagina'];
                    
                    if(!$pagina){
                    
                        $pc = "1";
            
                    }else{
                    
                        $pc = $pagina;
            
                    }
            
                    //Se não  for definida o valor da página sera atribuida 1 a mesma.
                    //Determinar valor inicial das buscas litimitadas.
            
            
                    //Verifica ou retorna o numero de registros no banco.
            
            
                    
            
                    $inicio = $pc - 1;
            
                    $inicio = $inicio * $total_registros_pagina;
            
            
            
                    $limite = mysqli_query($c -> conexao(),"$busca LIMIT $inicio,$total_registros_pagina");

                    $todos = mysqli_query($c -> conexao(),$busca);


                    
            
                    
                    $tr = mysqli_num_rows($todos);
            
                    $tp = $tr / $total_registros_pagina;
                    

                    //criando a visualização

                    ?>
                        <?php while($dados = mysqli_fetch_array($limite)){ ?>   

                        <td><?echo $dados[1]?></td>
                        <td><?echo $dados[2]?></td>
                        
                        <td><?echo $dados[3]?></td>
                        <td><a   href='cadastro.php?id=<?echo $dados[0]?>&nome=<?php $dados[1]?> &acao=editar &cpf=<?$dados[3]?>' > <img src='./icons/lapis1.png'></a>-<a  id="excluir" href='excluir.php?excluir=<?echo $dados[0]?>'> <img src='./icons/lixeira.png'>
                       
                       
                        </a></td>
                                                    
                   
                
                 
                    </tr>
                        

                        <?}?>

                       
                    </table>
                    <div class="clear"></div>

                    <?}?>
<?


$anterior = $pc - 1;
$proximo = $pc  + 1;

                    $id_atual = $_GET['id'];
            
            if($pc>1){
    
                echo "<a class='btn-anterior' href='?id=$id_atual&pagina=$anterior'><-Anterior</a>";
    
            }
    
            echo "|";
    
    
            if($pc<$tp){
    
    
            echo "<a class='btn-proximo' href='?id=$id_atual&pagina=$proximo'><-Proximo</a>";
                
            }
    

    ?>           
            </form>
            <table class="tabelaPesquisa" width="600px" align="center" border="1px solid black">

            <th>Pesquisa</th>
            <tr>
              
                 <ul>           
                
                <td> <li class='resultado'></li></td>

                </ul> 

            </tr>

            <tr>
            <?



        

     

//Botoes proximo e anterior;




        ?>
                
        </tr>

        </table>
<?

     

?>
          
    </body>
    
</html>
  • It wasn’t clear your question, better organizing your code I can help you better

  • The value coming from the bank is being printed without space or everything together MAUROROCHA EU QUERO ESPACO between the name and the over, Uro rock.

  • Blackcode and @Rodrigoalves users. Stack Overflow is not a forum, we are a site of questions and answers, do not use the space of answers to weave dialogues.

  • Share your code, or project, either through Git or online so we can see what you’re doing, I’m willing to help you solve it. then put the solution here.

1 answer

0

Well, I’ve never seen that happen. A hint, change as logic: try this way here:

$mysqli = new mysqli("localhost","my_user","my_password","my_db");

if ($mysqli -> connect_errno) {
  echo "Failed to connect to MySQL: " . $mysqli -> connect_error;
  exit();
}

$sql = "SELECT Lastname, Age FROM Persons ORDER BY Lastname";
$result = $mysqli -> query($sql);

// Numeric array
$row = $result -> fetch_array(MYSQLI_NUM);
printf ("%s (%s)\n", $row[0], $row[1]);

adjust to your code and see if it fits.

Abs

Browser other questions tagged

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