Error (T_variable) in php, how to resolve?

Asked

Viewed 273 times

1

I have an error when connecting in the database,php says it does not recognize the line.

He makes the following mistake : Parse error: syntax error, Unexpected '$conexao' (T_VARIABLE) in C: xampp htdocs Site formcadastro conexao2.php on line 6

My code in php :

<?PHP
$host = "localhost";
$user = "root";
$pass =  "";
$banco = "cadastrocli"
$conexao = mysql_connect($host,$user,$pass) or die(mysql_error());
mysql_select_db($banco) or die(mysql_error());


$idCad       = $_POST ['idCad'];
$nome       = $_POST ['Nome'];      
$email      = $_POST ['Email']; 
$senha      = $_POST ['Senha']; 
$confirmar  = $_POST ['Confirmar']; 
$telefone   = $_POST ['Telefone'];  
$celular    = $_POST ['Celular'];
$nascimento = $_POST ['Nascimento'];
$sexo       = $_POST ['Sexo'];
$bairro     = $_POST ['Bairro'];
$cidade     = $_POST ['Cidade'];
$estado     = $_POST ['Estado'];

$sql = mysql_query "(INSERT INTO cadastrocli (idCad, Nome, Email, Senha, Confirmar, Telefone, Celular, Nascimento, Sexo, Bairro, Cidade, Estado) 
VALUES ('$idCad', '$nome', '$email', '$senha', '$confirmar', '$telefone', '$celular', '$nascimento', '$sexo', '$bairro', '$cidade', '$estado');"
echo"Cadastro efetuado com sucesso;"            
?>

1 answer

1

Putting the ; in the previous line. All lines should end like this so as not to affect the others, arrange this:

$banco = "cadastrocli";

Although nothing will happen now, it is appropriate to do the same on the last line. Not only because you get used to always putting the semicolon, but also facilitates if later put new lines, you will not have the same error that occurs now.

Programming is having attention to detail.

Behold "working" in the ideone. Also put on the Github for future reference. Note that generates no error.

  • So I modified but still the error persists.

  • I edited the answer to show that it works. Then the problem is another and specific in your environment. Then we have no way of knowing what happens. The reason for closing the question remains the same, because it is either a typo or it cannot be reproduced. Take a look if you’re not doing something wrong, if you’re saving the edited one at the right place, if the mistake has moved. If you have another error, open another question.

  • In Google while trying to run, keeps giving the same error,It is not typing error because I have already checked, what can be if it is an error in the variables when being called.

  • But google does not run code.

  • It was clearly a typo, so if you have another problem, open a new question with enough information to help. The only thing I can add that this code is asking for is to take an attack and steal and destroy the database. And I don’t know what Google means in this context. The contexts I know, it doesn’t really work, it’s not his job to run PHP code. If you want help, give enough information to be helped. Playing words without nexus will not help you.

Browser other questions tagged

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