Error Parse error: syntax error, unexpected 'mysql_query' (T_STRING) [closed]

2

Well I'm trying to do a "PHP and MySQL Registration System" I did this following all the instructions passed to me 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 \ Form \ domain.php on line 25

Below is 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 ...

So could you help me find the error?

    
asked by anonymous 02.06.2015 / 01:36

2 answers

4
  

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

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

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

$sql mysql_query("....

Switch to:

$sql = mysql_query("

As a beginner, I recommend not using the mysql_ * functions they are obsolete.

Required reading:

Why should not we use functions of type mysql_ *?

MySQL vs PDO - Which is the most recommended to use?

Common error - mysql_fetch_array () expects parameter 1 to be resource, boolean given in

    
02.06.2015 / 01:40
3

You did not assign the variable $sql , forgot = , to let it work correctly use $sql = mysql_query( , do not use @ before, this will omit the errors, you have to treat them correctly not to stay with a "dirty" code.

But first of all, I no longer recommend using mysql_query* it has become deprecated,

Since you are a beginner, use mysqli

But as I evolve, I strongly recommend PDO , as it is safer and object oriented.

    
02.06.2015 / 01:55