search.php
<html>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script> //클라이언트 페이지에 보여주기 위해 ajax사용 그냥 서버페이지에서 보여주고 싶으면 사용안하면 됌
function add() {
var data = $('#sear').val();
$.ajax({
url: "/searchRE.php", //입력값을 보낼 주소
type: "get", //get,post 데이터 타입
data: {sear: $('#sear').val()}, //
success : function(data){
$('#aaa').html(data); //p테그 id 값에 받아온 데이터 출력
console.log(data);
},
});
}
</script>
<p id="aaa"></p>
<input type="text" id="sear" placeholder="id입력">
<button onclick="add()" >찾기</button>
</html>
searchRE.php
<?php
include $_SERVER['DOCUMENT_ROOT']. "/test/dbconn.php";
$sear = $_GET['sear'];
$sql="select*from login where id='$sear'";
$row=mysqli_query($conn,$sql);
$total= mysqli_num_rows($row); //db에서 값이 몇개 존재 하는지 알수 있다 0개면 아이디가 없기 때문에 찾을수 없음
echo $total."<br>";
if($total==1){
while($result = mysqli_fetch_array($row)){ //배열을 while 데이터를 뽑아 준다
echo "id : ".$result['id']."<br>"."name : ".$result['name']."<br>"."email : ".$result['email']."<br>"."date : ".$result['date'];
}
}else{
echo "<script>alert('없는 아이디입니다');history.back();</script>";
return false;
}
?>
간단한 ajax로 아이디 찾기 예제
[PHP] php 디비 사용 하는 법 dbconn.php (0) | 2021.12.17 |
---|---|
[PHP] cookie 사용하여 ID저장 하기 (2) | 2021.11.30 |
[PHP] script 에서 session 값 불러오기 (0) | 2021.11.25 |
[PHP] javascript keyup 숫자만 입력 가능 하게 숫자 정규식 (0) | 2021.11.23 |
[PHP] 회원가입 아이디 중복검사/유효성 체크 html형식으로 출력 (0) | 2021.11.17 |
댓글 영역