I have the following errors My head is frying too much and I can not see the error.
Notice: Undefined index: cxname
Notice: Undefined index: search
Follow the codes
<?php
try {
$con = new PDO('mysql:host=localhost;dbname=XXX', 'root', 'XXX');
} catch (PDOException $e) {
print $e->getMessage();
}
?>
<form name="form1" method="post" action="">
<label>
<input name="cxnome" type="text" id="cxnome" value="" size="30">
</label>
<label></label>
<label>
<input type="submit" name="pesquisar" value="Pesquisar">
</label>
<label>
<input type="reset" name="Submit2" value="Limpar">
</label>
</form>
<?php
$nome=$_POST['cxnome'];
$pesquisa=$_POST['pesquisar'];
if(isset($pesquisa)&&!empty($nome))
{
$stmt = $con->prepare("SELECT * FROM usuarios WHERE nome LIKE :letra");
$stmt->bindValue(':letra', '%'.$nome.'%', PDO::PARAM_STR);
$stmt->execute();
$resultados = $stmt->rowCount();
if($resultados>=1){
echo "Resultado(s) encontrado(s): ".$resultados."<br /><br />";
while($reg = $stmt->fetch(PDO::FETCH_OBJ))
{
echo $reg->nome." - ";
echo $reg->email."<br />";
}
}
else
{
echo "Não existe usuario cadastrado";
}
}
else{
echo "Preencha o campo de pesquisa";
}
?>