Parse error: syntax error, Unexpected 'mysql_query' (T_STRING)

Asked

Viewed 1,523 times

2

Well I’m trying to make a "Registration System with PHP and Mysql" I did this by following all the instructions I gave but at the time of the result it returns the following message.

Parse error: syntax error, Unexpected 'mysql_query' (T_STRING) in C: wamp www Formulario cadastrado.php on line 25

Below goes my code

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Formulário de inscrição</title>
    </head>

    <body>
        <?php
            $host = "localhost";
            $user = "root";
            $pass = "";
            $banco = "cadastro";
            $conexao = mysql_connect($host, $user, $pass) or die (mysql_error());
            mysql_select_db($banco)or die(mysql_error());
        ?>
        <?php
            $nome = $_POST['nome'];
            $sobrenome = $_POST['sobrenome'];
            $dataNasc = $_POST['dataNasc'];
            $telefone = $_POST['telefone'];
            $email = $_POST['email'];
            $bairro = $_POST['bairro'];
            $comentarios = $_POST['comentarios'];
            $sql mysql_query("INSERT INTO funcionarios(nome, sobrenome, nascimento, telefone, email, bairro, comentarios)VALUES('$nome', '$sobrenome', '$dataNasc', '$telefone', '$email', '$bairro', '$comentarios')");
        ?>
    </body>
</html>

And now a print that I think can help... inserir a descrição da imagem aqui

Then you could help me find the mistake?

  • Welcome. Do not use Stacksnippets for PHP code. PHP does not work on it, the boxes are marked with css/js/html so just post this inside them. For questions with code that cannot be reproduced via browser use the icon that looks like this { }. Do not use title, Beginner, Helping, Help, Please. Use intuitive titles that have to do with the problem, follow the example of the other questions you can see on the home page.

  • Enjoy and see the php wiki there are some good tips and materials to start.

2 answers

4


Parse error: syntax error, Unexpected 'mysql_query' (T_STRING)

Syntax error it says more or less 'something is out of place/right order', here it is necessary to make an assignment use the equal sign(=) for that reason.

mysql_query returns a Resource if successful otherwise returns a false which means that your query failed, so it is important to use the mysql_error() to know if the query has an error or if it was generated due to bank restriction violation.

$sql mysql_query("....

Change to:

$sql = mysql_query("

Since you are still a beginner, I recommend not using mysql_* functions they are obsolete.

Must-read:

Why should we not use mysql type functions_*?

Mysqli vs PDO - which is the most recommended to use?

Common error - mysql_fetch_array() expects Parameter 1 to be Resource, Boolean Given in

  • Wow... I changed that and the mistake went to line 14.. And I remember seeing somewhere that @beforemysql_connect should be added and I was able to get the bug out.. Thank you very much, rray

  • Do not use @ it omits the error, the right is to treat them. @naldson

  • "It’s right to treat them." Like?

  • If the project is legacy(old) make sure to always see the error generated by the bank, in this case you need to use the mysql_error(). Like this: mysql_query($sql) or die(mysql_error()); @Naldson

3

You did not assign the variable $sql, forgot the =, to leave working properly use $sql = mysql_query(, don’t use @ before, this will omit the errors, you have to treat them properly not to be with a code "dirty".

But first of all, I no longer recommend using the mysql_query* she became obsolete,

Since you’re a beginner, use mysqli

but when evolving, I strongly recommend the PDO, as it is safer and object-oriented.

Browser other questions tagged

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