전자 메일을 입력 한 후에 전자 메일을 사용할 수 있는지 (db에 존재하지 않는지) 또는 존재하지 않는지 (db에 존재하는지)를 자동으로 표시합니다. 입력 할 때 표시되는 출력이 없습니다. 현재이 코드가 있습니다. 내가이PHP와 AJAX를 사용하여 서버 측 유효성 검사에 문제가 있음
가 여기 내 메인 페이지 코드의
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Jquery-ajax Practice</title>
</head>
<body>
<section>
<form>
<label for="text_email">E-mail:</label>
<input id="text_email" type="email" >
<script type="text/javascript" charset="utf-8" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js">
$(document).ready(function(){
$('#text_email').keyup(function(){
email($(this).val());
});
});
function email(str){
$.post('checkmail.php',{ email: str},
function(data){
$('#check_email').html(data.returnValue);
}, 'json');
}
</script>
<label for="text_email" id="check_email"></label>
</form>
</section>
</body>
</html>
여기 내 PHP 코드 내가 볼 수
<?php
if(isset($_POST['email']))
{
try
{
$pdo=new PDO('mysql:host=localhost;dbname=class;charset=utf-8', 'root');
}
catch(PDOException $e)
{
echo 'Failed: '.$e->getMessage();
}
$stmt=$pdo->prepare('SELECT email FROM class where email=:email LIMIT 1');
$stmt->execute(array(':email'=>$_POST['email']));
if($stmt->rowCount()>0)
{
$check='E-mail cannot be use.';
}
else
{
$check='E-mail can be use.';
}
echo json_encode(array('returnValue'=>$check));
}
?>
코드가 빠르게 보입니다. 오류가 있습니까? 예상대로 작동하지 않습니까? – mittmemo
당신은 가지고있는 문제에 관해 구체적이고, 대답할만한 질문을해야합니다. "여기 내 코드가 있는데 어떻게 향상시킬 수 있습니까?" Stack Overflow의 정의에 의한 질문이 아닙니다. – meagar
[코드 검토] (http://codereview.stackexchange.com)가 더 적절할 수도 있습니다. –