Enviando dados para o banco de dados erro
Gente ao envia um cadastro para o banco de dados ele da os seguintes erro:
eu sei o que significam, mais não sei o por que esta dando errado.
Notice: Undefined index: nome in C:\xampp\htdocs\diamond_black\formulario\acesso_cadastro.php on line 12
Notice: Undefined index: rua in C:\xampp\htdocs\diamond_black\formulario\acesso_cadastro.php on line 13
Notice: Undefined index: bairro in C:\xampp\htdocs\diamond_black\formulario\acesso_cadastro.php on line 14
Notice: Undefined index: numero in C:\xampp\htdocs\diamond_black\formulario\acesso_cadastro.php on line 15
Notice: Undefined index: complemento in C:\xampp\htdocs\diamond_black\formulario\acesso_cadastro.php on line 16
Notice: Undefined index: tel in C:\xampp\htdocs\diamond_black\formulario\acesso_cadastro.php on line 17
Notice: Undefined index: cel in C:\xampp\htdocs\diamond_black\formulario\acesso_cadastro.php on line 18
Notice: Undefined index: cep in C:\xampp\htdocs\diamond_black\formulario\acesso_cadastro.php on line 19
Notice: Undefined index: cpf in C:\xampp\htdocs\diamond_black\formulario\acesso_cadastro.php on line 22
Notice: Undefined variable: dbh in C:\xampp\htdocs\diamond_black\formulario\acesso_cadastro.php on line 31
Fatal error: Call to a member function prepare() on a non-object in C:\xampp\htdocs\diamond_black\formulario\acesso_cadastro.php on line 31
Código php
Código php exemplo:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Documento sem título</title>
</head>
<body>
<?php
header('Content-Type: text/html; charset=utf-8', true);
$nome=$_POST['nome'];
$rua=$_POST['rua'];
$bairro=$_POST['bairro'];
$numero=$_POST['numero'];
$complemento=$_POST['complemento'];
$tel=$_POST['tel'];
$cel=$_POST['cel'];
$cep=$_POST['cep'];
$email=$_POST['email'];
$senha=$_POST['senha'];
$cpf=$_POST['cpf'];
$pdo=new PDO("mysql:localhost;dbname=usuarios","root","");//conecta ao banco
if($_POST)
{
$stmt = $dbh->prepare("INSERT INTO usuarios(nome,rua,bairro,numero,complemento,tel,cel,cep,email,senha,cpf) VALUES ('$nome','$rua','$bairro','$numero','$complemento','$tel','$cel','$cep','$email','$cpf','$senha'");//inserção no banco
$stmt->bindParam(':nome', $name);
$stmt->bindParam(':rua', $rua);
$stmt->bindParam(':bairro', $bairro);
$stmt->bindParam(':numero', $numero);
$stmt->bindParam(':complemento', $complemento);
$stmt->bindParam(':tel', $tel);
$stmt->bindParam(':cel', $cel);
$stmt->bindParam(':cep', $cep);
$stmt->bindParam(':email', $email);
$stmt->bindParam(':senha', $senha);
$stmt->bindParam(':cpf', $cpf);
// insert one row
$name = 'one';
$rua = 1;
$stmt->execute();
error_reporting(-1);
}
else
{
echo "<script>alert('Os dados inseridos já estão cadastrados, favor fazer o login');back.hystory;</script>";
}
?>Discussão (20)
Carregando comentários...