place id in javascript + detect $row statement in PDO
Posted: 05 Dec 2019, 17:19
I have a little script to detect if a member is placed in database
but I dont understand how to detect $row in javascript
also I don`t known how to place a extra line in my PDO doc
for $row = $stmt->fetch(PDO::
index
if(data == "Match Found")
$('#search-result-container').html("
Here I try to add the <?php echo $row['post_id'];?>
I would like to detect $row with this simple php code
but it is not working
but I dont understand how to detect $row in javascript
also I don`t known how to place a extra line in my PDO doc
for $row = $stmt->fetch(PDO::
index
Code: Select all
<script>
$(document).ready(function() {
$('#search-data').blur(function(e) {
var value = $(this).val();
liveUsernameSearch(value);
});
});
function liveUsernameSearch(val){
$('#preloader-gif').show();
$.post('controller.php',{'search-data': val}, function(data){
if(data == "Match Found")
$('#search-result-container').html("<span style='color:green;font-weight:bold;'> <?php ['name'] ?> <?php $name ?> Username is available</span>");
else
$('#search-result-container').html("<span style='color:red;font-weight:bold;'>Username is not available</span>");
$('#preloader-gif').hide();
}).fail(function(xhr, ajaxOptions, thrownError) { //any errors?
alert(thrownError); //alert with HTTP error
});
}
</script>
$('#search-result-container').html("
Here I try to add the <?php echo $row['post_id'];?>
Code: Select all
public function searchData($searchVal){
try {
$dbConnection = $this->dbConnect();
$stmt = $dbConnection->prepare("SELECT * FROM `user` WHERE `name` = :searchVal");
$stmt->bindParam(':searchVal', $searchVal , PDO::PARAM_STR);
$stmt->execute();
$Count = $stmt->rowCount();
//echo " Total Records Count : $Count .<br>" ;
$result ="" ;
if ($Count > 0){
$result = "Match Found" ;
}else{
$result = "Match Not Found" ;
}
return $result ;
but it is not working
Code: Select all
$row = $stmt->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_LAST);