Error: Parse error: syntax error, unexpected '}' [closed]

-4

The code with problem does the following: It is part of a password reset system that I am creating, but when I put it inside an ECHO I got some problems that I could solve because I do not see an apparent solution.

echo ''
    .$id = $_GET['id']; // Recebendo o valor vindo do link
    $resultado = $mysqli->query("SELECT * FROM usuarios WHERE ID = '".$id."'"); // Há variável $resultado faz uma consulta na tabela selecionando somente o registro desejado
    while($linha = mysqli_fetch_array($resultado))
    {'
    <html><form id="form_Usuario" method="POST" action="updatecomplete.php" >
        <label> Senha: </label> <br />
            <input type="password" name="pass" style="height:30px; width:250px" value="'.md5($linha['Senha']).'\" />
            <input type="submit" value="Alterar Senha" />
    </form></html>
       '}

When I run the code I get the following error:

  

Parse error: syntax error, unexpected '}' in ...

    
asked by anonymous 15.12.2015 / 23:26

2 answers

0

A semicolon was missing at the end of your string.

</form></html>
   '} <--- aqui

To anticipate and facilitate the identification of syntax errors, use an IDE or some highlighter text editor.

The code of the question seems to want to make an edit, so only a record is only returned, it is not necessary while, however formatting the html and imbutirr the php in it is important not to create a messy code.

Do not put variables directly in the SQL statement, this makes your code vulnerable to sqlinjections, solves this with prepared statements.

<?php
    $id = !empty($_GET['id']) && ctype_digit($_GET['id']) ? $_GET['id'] : 0;
    $stmt = $mysqli->prepare("SELECT * FROM usuarios WHERE ID = ?");
    $stmt->bind_param('i', $id);
    $stmt->execute();
    $result = $stmt->get_result();
    $registro = $result->fetch_assoc();
 ?>   

<html>
    <form id="form_Usuario" method="POST" action="updatecomplete.php" >
        <label> Senha: </label> <br />
        <input type="password" name="pass" style="height:30px; width:250px" value="<?php echo md5($registro['Senha']); ?>" />
        <input type="submit" value="Alterar Senha" />
    </form>
</html>
    
15.12.2015 / 23:30
2

To display html next to php should use echo or:

?> seu html aqui <?php

So:

while($linha = mysqli_fetch_array($resultado))
{
?>
<html><form id="form_Usuario" method="POST" action="updatecomplete.php" >
    <label> Senha: </label> <br />
        <input type="password" name="pass" style="height:30px; width:250px" value="<?php echo md5($linha['Senha']); ?>" />
        <input type="submit" value="Alterar Senha" />
</form></html>
<?php
}

Probably had problems because here you tried to "escape" the quote ( " ) without need, so use if you use echo:

echo ''
    .$id = $_GET['id']; // Recebendo o valor vindo do link
    $resultado = $mysqli->query("SELECT * FROM usuarios WHERE ID = '".$id."'"); // Há variável $resultado faz uma consulta na tabela selecionando somente o registro desejado
    while($linha = mysqli_fetch_array($resultado))
    {

    echo '<html><form id="form_Usuario" method="POST" action="updatecomplete.php" >
        <label> Senha: </label> <br />
            <input type="password" name="pass" style="height:30px; width:250px" value="' . md5($linha['Senha']) . '" />
            <input type="submit" value="Alterar Senha" />
    </form></html>';
    }

I recommend that you learn the basics of following the documentation:

15.12.2015 / 23:29