我对下面的代码有疑问和问题。
的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
available.php
许多人告诉您需要清理或转义每个POST
和GET
数据。那么最适合PDO的是什么。还听说逃避不能与PDO合作可能是我错了吗?