Online error of the form

Asked

Viewed 29 times

1

In the browser of the following error, I have tried everything if you can help

Parse error: syntax error, Unexpected $end, expecting T_VARIABLE or T_DOLLAR_OPEN_CURLY_BRACES or T_CURLY_OPEN in

<?php
echo "NOVO MOTORISTA";
include('conexao.php');
if(isset($_POST['submitted'])){
    foreach($_POST AS $key=>$value){$_POST[$key] = mysql_real_escape_string($value);}
    $sql = "INSERT INTO 'motoristas'('cod_mot', 'nome', 'endereco', 'cidade','cod_veiculo')
    VALUES('{$_POST['cod_mot']}', '{$_POST['nome']}, '{$_POST['endereco']}, '{$_POST['cidade']}, '{$_POST['cod_veiculo']}')";
    mysql_query($sql) or die(mysql_error());
    echo "registro adicionado.<br/>";
    echo "<a href='listar_m.php'>Voltar à listagem</a>;
}
?>
<html>
<form action= method='POST'>
<p><b>Cod Mot:</b><br/><input type='text' name='cod_mot'/>
<p><b>Nome:</b><br/><input name='nome' type='text' size= '50'/>
<p><b>Endereco:</b><br/><input name='endereco' type='text' size='50'/>
<p><b>Cidade:</b><br/><input name='cidade' type='text' size='50'/>
<p><b>Cod Veiculo:</b><br/><input type='text' name='cod_veiculo'/>
<p><input type='submit' value='Salvar'/><input type='hidden' value='1' name='submitted'/>
</form>
  • Edit your post and post your code, please!

  • The error message does not appear to be complete, and there is no code referring to the error, such as the variable $end mentioned in the error

2 answers

2

This error may occur when a sequence has been opened and has not been closed (e.g., keys, brackets, quotes).

See in your code in the line below that it is missing 3 simple quotes in the insertion of values:

'{$_POST['nome']}, '{$_POST['endereco']}, '{$_POST['cidade']},

When the right thing would be:

             FALTANDO                FALTANDO               FALTANDO
                 ↓                       ↓                     ↓
'{$_POST['nome']}', '{$_POST['endereco']}', '{$_POST['cidade']}',

And missing a double quote on this line:

                                               FALTANDO
                                                  ↓
echo "<a href='listar_m.php'>Voltar à listagem</a>";

0

The last echo "<a href='listar_m.php'>Voltar à listagem</a>; does not have double quotes closing, complementing, the Insert command needs to have quotes ' before and after the {$_POST['valor'}

Browser other questions tagged

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