Jump to content


Photo

Erro Ao Cadastrar No Bd


  • Faça o login para participar
3 replies to this topic

#1 Kahor

Kahor

    12 Horas

  • Usuários
  • 230 posts
  • Sexo:Masculino

Posted 17/03/2010, 08:03

Bom dia,

Mexi em alguns itens no meu cadastro, aperto cadastrar e olha o que aparece:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'marco', 'marco', 'marco', 'v@', '19', '99999', 'marco', 'marco', 'marco', 'marco' at line 1 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'marco', 'marco', 'marco', 'v@', '19', '99999', 'marco', 'marco', 'marco', 'marco' at line 1 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'marco', 'marco', 'marco', 'v@', '19', '99999', 'marco', 'marco', 'marco', 'marco' at line 1You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'marco', 'marco', 'marco', 'v@', '19', '99999', 'marco', 'marco', 'marco', 'marco' at line 1

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[url="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd[/url]">
<html xmlns="[url="http://www.w3.org/1999/xhtml"]http://www.w3.org/1999/xhtml[/url]">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<table width="650" border="0" cellpadding="0" cellspacing="0">
  <!--DWLayoutTable-->
  <tr>
	<td width="224" height="140">&nbsp;</td>
	<td width="252">&nbsp;</td>
	<td width="174">&nbsp;</td>
  </tr>
  <tr>
	<td height="24">&nbsp;</td>
	<td valign="middle">
 <font color="#FF0000"><b>
 <?php
// inclui o arquivo de configuração do sistema
include "Config/config_sistema.php";

// recebe dados do formulario
$login = htmlspecialchars($_POST['login']);
$senha = $_POST['senha'];
$rep_senha = $_POST['rep_senha'];
$razao_social = htmlspecialchars($_POST['razao_social']);
$nome_responsavel = htmlspecialchars($_POST['nome_responsavel']);
$cnpj = $_POST['cnpj'];
$insc_est = $_POST['insc_est'];
$email = htmlspecialchars($_POST['email']);
$ddd = $_POST['ddd'];
$telefone = $_POST['telefone'];
$endereco = $_POST['endereco'];
$referencia = $_POST['referencia'];
$cidade = $_POST['cidade'];
$cep = $_POST['cep'];
$pergunta = htmlspecialchars($_POST['pergunta']);
$resposta = htmlspecialchars($_POST['resposta']);

// verifica se o usuario digitou o login
if($login == "") {
 echo "Digite seu login!";
 exit;
} else {
 // se o usuario digitou o login ele verifica
 // se esta disponivel
 $consulta = mysql_query("select * from dados_usuarios where Login = '$login'");
 $linha = mysql_num_rows($consulta);
 if($linha != 0) {
  echo "O nome de usuario que você<br>
 	Digitou já existe tente outro!";
  exit;
 }
}

// verifica se o usuario digitou a senha
if($senha == "") {
 echo "Digite sua senha!";
 exit;
} else {
 // se o usuario digitou a senha
 // vamos comparar com a contra senha
 if($senha != $rep_senha) {
  echo "Senha invalida!";
  exit;
 }
}

// verifica se o usuario digitou o nome
if($razao_social == "") {
 echo "Digite a Razão Social!";
 exit;
}

// verifica o email
if($nome_responsavel == "") {
 echo "Digite o nome do responsável!";
 exit;
}

// verifica o email
if($cnpj == "") {
 echo "Digite o CNPJ!";
 exit;
}

// verifica o email
if($insc_est == "") {
 echo "Digite a Inscrição Estadual!";
 exit;
}

// verifica o email
if($ddd == "") {
 echo "Digite o DDD!";
 exit;
}

// verifica o email
if($telefone == "") {
 echo "Digite o Telefone!";
 exit;
}

// verifica o email
if($endereco == "") {
 echo "Digite o endereço!";
 exit;
}

// verifica o email
if($referencia == "") {
 echo "Digite a referência!";
 exit;
}


// verifica a cidade
if($cidade == "") {
 echo "Digite a cidade onde você mora!";
 exit;
}

// verifica o cep
if($cep == "") {
 echo "Digite o CEP de onde você mora!";
 exit;
}

// verifica a pergunta secreta
if($pergunta == "") {
 echo "Digite sua pergunta secreta!";
 exit;
}

// verifica a resposta secreta
if($resposta == "") {
 echo "Digite sua resposta secreta!";
 exit;
}

// faz consulta no banco para inserir os dados do usuario

 

$sql = ("INSERT INTO dados_usuarios (login, senha, razao_social, nome_responsavel, cnpj, insc_est, email, ddd, telefone, endereco, referencia, cidade, cep, pergunta, resposta) VALUES ('$login', '$senha', '$razao_social, '$nome_responsavel', '$cnpj', '$insc_est', '$email', '$ddd', '$telefone', '$endereco', '$referencia', '$cidade', '$cep', '$pergunta', '$resposta')");
$consulta = mysql_query($sql) or die(mysql_error());

 

// verifica se o usuario foi cadastrado
if($consulta) {
 echo "<font color=green><b>
	Você foi cadastrado com sucesso!<br>
	Click <a href=index.php>aqui</a> para efetuar o login.
	</font></b>";
 exit;
} else {
 echo "Não foi possivel efetuar o seu cadastro<br>
	tente mais tarde pode ser um problema no servido!<br>
	Click <a href=index.php>aqui</a> para ir ate a home page do sistema.";
 exit;
}
?>

	<!--DWLayoutEmptyCell-->	&nbsp;</td>
	<td>&nbsp;</td>
  </tr>
  <tr>
	<td height="148">&nbsp;</td>
	<td>&nbsp;</td>
	<td>&nbsp;</td>
  </tr>
</table>
</body>
</html>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[url="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd[/url]">
<html xmlns="[url="http://www.w3.org/1999/xhtml"]http://www.w3.org/1999/xhtml[/url]">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
form {font: 14px Trebuchet MS;}
form input {font: 14px Trebuchet MS;}

form #loginsenha {
 margin-bottom: 20px;
 background-color: #CCC;
 width: 680px; height: 80px;
 display: block;}

form #loginsenha .txtform {
 float: left; text-align:right;
 width: 160px;
 margin-top: 2px; margin-right: 10px;}
 
form #loginsenha .form input {
 height: 14px;
 border: 1px solid #666;
 background-color: #FFF;}
 
form #loginsenha .form {
 float: right; text-align:left ;
 width: 500px;
 margin-top: 2px; margin-right: 10px;} 
 

 


form #dados {
 margin-bottom: 20px;
 background-color: #CCC;
 width: 680px; height: 100px;
 display: block;}

form #dados .txtform {
 float: left; text-align:right;
 width: 160px;
 margin-top: 5px; margin-right: 10px;}
 
form #dados .form input {
 height: 14px;
 border: 1px solid #666;
 background-color: #FFF;} 
 
form #dados .form {
 float: right; text-align:left ;
 width: 500px;
 margin-top: 5px; margin-right: 10px;} 
 
 
 
form #contato {
 margin-bottom: 20px;
 background-color: #CCC;
 width: 680px; height: 200px;
 display: block;}

form #contato .txtform {
 float: left; text-align:right;
 width: 160px;
 margin-top: 5px; margin-right: 10px;}

form #contato .form input#label8 {margin-right: 5px;}

form #contato .form input {
 height: 14px;
 border: 1px solid #666;
 background-color: #FFF;} 
 
form #contato .form {
 float: right; text-align:left ;
 width: 500px;
 margin-top: 5px; margin-right: 10px;} 
 
</style>
</head>

<body>
<form action="cadastra_usuario.php" method="post" enctype="multipart/form-data" name="formcadastro">
<span class="style1">Cadastro de usuarios </span>

<h2>Insira os seus dados para que possamos efetuar o cadastro!</h2><br />

<h3>Todos os campos sao obrigatórios</h3>

<div id="loginsenha">

<div class="txtform">Login:</div>
<div class="form"><label for="textfield"></label>
<input name="login" type="text" id="login" size="40" maxlength="200" /></div>

        	
<div class="txtform">Senha:</div>
<div class="form"><label for="label"></label>
<input name="senha" type="password" id="label" size="20" maxlength="15" /></div>

 

<div class="txtform">Repetir senha:</div>
<div class="form"><label for="label2"></label>
<input name="rep_senha" type="password" id="label2" size="20" maxlength="15" /></div>


</div><!-- /loginsenha -->
 
 
 
 
 

<div id="dados">
        	
<div class="txtform">Razão Social:</div>
<div class="form"><label for="label3"></label>
<input name="razao_social" type="text" id="label3" size="40" maxlength="200" /></div>


<div class="txtform">Nome do responsável:</div>
<div class="form"><label for="label4"></label>
<input name="nome_responsavel" type="text" id="label4" size="40" maxlength="200" /></div>


<div class="txtform">CNPJ:</div>
<div class="form"><label for="label5"></label>
<input name="cnpj" type="text" id="label5" size="40" maxlength="200" /></div>

<div class="txtform">Inscrição Estadual:</div>
<div class="form"><label for="label6"></label>
<input name="insc_est" type="text" id="label6" size="40" maxlength="150" /></div>

</div><!-- /dados -->

 

 


<div id="contato">

<div class="txtform">E-mail:</div>
<div class="form"><label for="label7"></label>
<input name="email" type="text" id="label7" size="30" maxlength="150" /></div>

        	
<div class="txtform">Telefone com DDD:</div>
<div class="form">
<label for="label8"></label><input name="ddd" type="text" id="label8" size="2" maxlength="2" /><label for="label9"></label><input name="telefone" type="text" id="label9" size="10" maxlength="8" /></div>


<div class="txtform">Endereço completo:</div>
<div class="form"><label for="label10"></label>
<input name="endereco" type="text" id="label10" size="40" maxlength="200" /></div>


<div class="txtform">Referência:</div>
<div class="form"><label for="label11"></label>
<input name="referencia" type="text" id="label11" size="40" maxlength="200" /></div>


<div class="txtform">Cidade/UF:</div>
<div class="form"><label for="label12"></label>
<input name="cidade" type="text" id="label12" size="40" maxlength="50" /></div>


<div class="txtform">CEP:</div>
<div class="form"><label for="label13"></label>
<input name="cep" type="text" id="label13" size="40" maxlength="8" /></div>

 


<div class="txtform">Pergunta secreta:</div>
<div class="form"><label for="label14"></label>
<input name="pergunta" type="text" id="label14" size="40" maxlength="200" /></div>


<div class="txtform">Resposta secreta:</div> 
<div class="form"><label for="label15"></label>
<input name="resposta" type="text" id="label15" size="40" maxlength="200" /></div>

</div><!-- /form -->

<div class="form">
<label for="Submit"></label>
<input type="submit" name="cadastrar" value="Cadastrar" id="cadastrar" />

<label for="label13"></label>
<input type="reset" name="limpar" value="Limpar dados" id="label13" />
</form>
</body>
</html>




#2 MBA

MBA

    24 Horas

  • Usuários
  • 412 posts
  • Sexo:Masculino
  • Localidade:Belo Horizonte
  • Interesses:Desenvolvimento WEB

Posted 17/03/2010, 08:25

Amigo, bom dia.
Primeiramente, de uma olhada na sua query.
Está faltando uma ' na razão social!

Dica:
Se você escreve sua query toda em uma linha, a mensagem de erro não vai lhe ajudar.
Tente quebrar linhas na query:

$sql = ("INSERT INTO dados_usuarios (login, senha, razao_social,
 nome_responsavel, cnpj, insc_est, email, ddd,
 telefone, endereco, referencia, cidade, cep,
 pergunta, resposta) 
              VALUES 
                     ('$login', '$senha', '$razao_social,
 '$nome_responsavel', '$cnpj', '$insc_est', '$email', 
'$ddd', '$telefone', '$endereco', '$referencia', 
'$cidade', '$cep', '$pergunta', '$resposta')");

$consulta = mysql_query($sql) or die(mysql_error());


Outra dica:
Se você encostar seu problema e postar no fórum apenas o que é de interesse para quem está lhe ajudando, sempre terá mais respostas....

E dica final:
Estude MVC =D Irá lhe poupar de erros como esse!

Abraços e um bom dia.
Mateus Antunes
Mateus Antunes
MBASistemas

#3 Kahor

Kahor

    12 Horas

  • Usuários
  • 230 posts
  • Sexo:Masculino

Posted 17/03/2010, 08:53

@MBA

Bom dia..

Deu certo mesmo, tava mexendo em tudo aqui e nem vi isso =/

Para principio eu nao sei nada de nada de PHP, sou da parte xHTML/CSS aqui do fórum, e esses dias resolvi que tenho que aprender na marra.

Mas eu nao entendi o que posto:

Outra dica:
Se você encostar seu problema e postar no fórum apenas o que é de interesse para quem está lhe ajudando, sempre terá mais respostas....

E dica final:
Estude MVC =D Irá lhe poupar de erros como esse!


Valeu pela ajuda (y)

#4 MBA

MBA

    24 Horas

  • Usuários
  • 412 posts
  • Sexo:Masculino
  • Localidade:Belo Horizonte
  • Interesses:Desenvolvimento WEB

Posted 17/03/2010, 09:13

Sem problemas... Estamos todos aqui para aprender!
(Agora já sem quem eu procuro quando aparecerem problemas com HTML/CSS)
=D

Outra dica:
Se você encostar seu problema e postar no fórum apenas o que é de interesse para quem está lhe ajudando, sempre terá mais respostas....

Só estou comentando que o problema que enfrentava não precisa do código completo.
A query bastaria...

E dica final:
Estude MVC =D Irá lhe poupar de erros como esse!

Depois procure no Google que vai entender. É uma metodologia de desenvolvimento.

ABraços.
Mateus Antunes
Mateus Antunes
MBASistemas




1 user(s) are reading this topic

0 membro(s), 1 visitante(s) e 0 membros anônimo(s)

IPB Skin By Virteq