Reputation: 1085
I have a problem and a question for the code below.
index.php
<script type="text/javascript">
$(document).ready(function(){
$('#un').keyup(function(){
var username = $(this).val();
var Result = $('#result');
if(username.length > 2 || username.length > 11) { // if greater than 2 (minimum 3)
Result.html('./img/loadgreen.gif');
var dataPass = 'action=availability&username='+username;
$.ajax({ // Send the username val to available.php
type : 'POST',
data : dataPass,
url : 'available.php',
success: function(responseText){ // Get the result
if(responseText == 0){
Result.html('<span class="success">Available</span>');
}
else if(responseText > 0){
Result.html('<span class="error">Unavailable</span>');
}
else{
alert('Problem with sql query');
}
}
});
}else{
Result.html('Enter 3 to 11 characters');
}
if(username.length == 0) {
Result.html('');
}
});
});
</script>
<table>
<tr>
<td>
<input type="text" name="username" id="un" placeholder="Username" class="username" />
</td>
<td class="result" id="result"></td>
</tr>
</table>
available.php
<?php
include ( "./inc/connect.php" );
if(isset($_POST['action']) && $_POST['action'] == 'availability')
{
$username = $_POST['username'];
$que=$db->prepare("SELECT username FROM users WHERE username=:username");
$que->execute(array(':username'=>$username));
$count = $que->rowCount();
echo $count;
}
?>
POST
on available.php
lot of people tell you need to sanitize or escape every POST
and GET
data. So what works best with PDO. Also heard escaping doesn't works with PDO may be I am wrong?Upvotes: 1
Views: 721