Implode is not working right

Asked

Viewed 37 times

-1

I’m using this code

    include_once('../conexao.php'); 
    $query = "SELECT titulo FROM info";
    $result = mysqli_query($conexao, $query);
    $titulo = mysqli_fetch_assoc($result);
    <input type="text" class="form-control" id="tp_Control" placeholder="Digite o título" value=<?php echo implode($titulo) ?>>

The above code takes the title of the page that is in the database and puts it in the text box, but every time I check the text box the title is not being shown at all, after the space it disappears, but when I look at the title of the page it samples all, without the cut. And the code I use for the title is this.

<title><?php echo implode($titulo) ?></title>

É isso que sempre acontece

Does anyone have any idea what it might be?

  • How about trying to embrace input value with quotes? .... value="<? php echo implode($title) ?>">

1 answer

1


The input is being loaded as follows: (note that the word Automatica is in red which means it is an attribute)

<input type="text" class="form-control" id="tp_Control" placeholder="Digite o título" 
value=Lavagem Automatica>

note the value/value property value=Lavagem Automatica

The problem is the lack of quotation marks on the value=" " or value=' ', it is treating the word Automatica as if it were an attribute of the text field.

The correct is:

<input type="text" class="form-control" id="tp_Control" placeholder="Digite o título" 
value="<?php echo implode($titulo) ?>">

what will result from: (note that the word Automatica is no longer in red which means It is not an attribute)

<input type="text" class="form-control" id="tp_Control" placeholder="Digite o título" 
 value="Lavagem Automatica">

Attributes define a desired behavior or indicate additional properties of the elements. Most attributes require a value. In HTML, the value can be added without quotation marks if it has no spaces (name=value), or it must be added with single or double quotation marks (name='value such' or name="such value")

  • I’m still learning PHP, thank you so much for the help, and thank you so much for the explanation, it was excellent.

Browser other questions tagged

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